powershell-7.5-features について
PowerShell 7.5の機能と7.6プレビューを解説するリファレンススキルです。スクリプト作成者や管理者向けに、コマンドレットの変更、性能、パッケージ管理の更新を例とともにまとめています。
主な機能
- 01オブジェクトをCLI XML文字列にシリアライズ
- 02更新日時によるパスの絞り込み
- 03Webレスポンスの保存と内容の取得
- 04コメントや末尾カンマ付きJSONの解析
- 05ワイルドカードで隠しファイルを検索
- 06PSResourceGetとランタイムの更新を確認
活用シーン
- 01コマンド間でシリアライズ済みオブジェクトを渡す
- 02古いログファイルの削除を自動化
- 03HTTPステータスを確認しながらファイルをダウンロード
- 04コメント付き設定JSONを検証
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ josiahsiegel/ claude-plugin-marketplace --skill powershell-7.5-featuresインストール後、Claude Code で/powershell-7.5-featuresを入力して読み込まれたか確認します。
同梱ファイルreferences/powershell-7-6-preview.md
詳細
PowerShell 7.5/7.6 の機能
バージョン概要
| バージョン | ステータス | .NET | リリース |
|---|---|---|---|
| 7.5.4 | 安定版(LTS) | .NET 9.0.306 | 2025 年 10 月 |
| 7.6.0-preview.6 | プレビュー | .NET 10.0.0 GA | 2025 年 12 月 |
PowerShell 7.5 は、現在の安定版 LTS(長期サポート)リリースです。PowerShell 7.6 はプレビュー段階で、2026 年初頭の GA を目指す新機能が搭載されています。
PowerShell 7.5 の機能
PowerShell 7.5 GA(一般提供:2025 年 1 月)— 最新の安定版 7.5.4(2025 年 10 月)は、.NET 9.0.306 をベースに構築され、パフォーマンスとメモリ効率が大幅に向上しています。
新しいコマンドレット
ConvertTo-CliXml と ConvertFrom-CliXml
ファイルの入出力を行わずに、オブジェクトを CLI XML 形式に変換、または CLI XML 形式から変換します。
# ConvertTo-CliXml - Convert object to XML string
$process = Get-Process -Name pwsh
$xmlString = $process | ConvertTo-CliXml
# ConvertFrom-CliXml - Convert XML string back to object
$restored = $xmlString | ConvertFrom-CliXml
$restored.ProcessName # Outputs: pwsh
# Use cases:
# - Serialize objects for API transmission
# - Store object state in databases/caches
# - Share objects across PowerShell sessions
# - Clipboard operations with rich objects
Export/Import-Clixml との違い:
Export-Clixml:ファイルに書き込みますConvertTo-CliXml:文字列を返します(ファイルの入出力はありません)
強化された Test-Path コマンドレット
-OlderThan および -NewerThan パラメーター
更新日時でパスをフィルター処理します。
# Find files older than 30 days
Test-Path "C:\Logs\*.log" -OlderThan (Get-Date).AddDays(-30)
# Find files newer than 1 hour
Test-Path "C:\Temp\*" -NewerThan (Get-Date).AddHours(-1)
# Cleanup old log files
Get-ChildItem "C:\Logs" -Filter "*.log" |
Where-Object { Test-Path $_.FullName -OlderThan (Get-Date).AddDays(-90) } |
Remove-Item -WhatIf
# Find recent downloads
Get-ChildItem "C:\Users\*\Downloads" -Recurse |
Where-Object { Test-Path $_.FullName -NewerThan (Get-Date).AddDays(-7) }
ユースケース:
- ログローテーションの自動化
- バックアップファイルのクリーンアップ
- 最近更新されたファイルの監視
- キャッシュの無効化
強化された Web コマンドレット
-OutFile と併用する -PassThru
応答をファイルに保存し、同時に内容も返します。
# Before PowerShell 7.5 (choose one):
Invoke-WebRequest -Uri $url -OutFile "download.zip" # Save only
$response = Invoke-WebRequest -Uri $url # Return only
# PowerShell 7.5 (both):
$response = Invoke-WebRequest -Uri $url -OutFile "download.zip" -PassThru
$response.StatusCode # 200
# File also saved to download.zip
# Download and verify
$result = Invoke-RestMethod -Uri "https://api.example.com/data.json" `
-OutFile "data.json" `
-PassThru
Write-Host "Downloaded $($result.Length) bytes"
# File saved to data.json
利点:
- ダウンロードの進行状況を追跡
- HTTP ヘッダーを確認
- ステータスコードを検証
- ファイルへの保存と内容の処理を組み合わせ可能
強化された Test-Json コマンドレット
IgnoreComments と AllowTrailingCommas
柔軟な JSON 形式を解析します。
# JSON with comments (previously invalid)
$jsonWithComments = @"
{
// This is a comment
"name": "example", // inline comment
/* Multi-line
comment */
"version": "1.0"
}
"@
# PowerShell 7.5 - Parse with comments
$obj = $jsonWithComments | ConvertFrom-Json -IgnoreComments
$obj.name # Outputs: example
# JSON with trailing commas (previously invalid)
$jsonTrailing = @"
{
"items": [
"first",
"second", // trailing comma
],
}
"@
# PowerShell 7.5 - Parse with trailing commas
$obj = $jsonTrailing | ConvertFrom-Json -AllowTrailingCommas
# Validate JSON with relaxed syntax
Test-Json -Json $jsonWithComments -IgnoreComments
Test-Json -Json $jsonTrailing -AllowTrailingCommas
ユースケース:
- コメント付きの構成ファイルを解析
- JavaScript ツールからの JSON を処理
- API からの柔軟な JSON を受け入れ
- 構成ファイルを検証
強化された Resolve-Path と Convert-Path
ワイルドカードで隠しファイルを指定する -Force パラメーター
ワイルドカードを使用して、隠しファイルやシステムファイルにアクセスします。
# PowerShell 7.4 and earlier - Hidden files not matched
Resolve-Path "C:\Users\*\.*" | Select-Object -First 5
# Skips .vscode, .gitignore, etc.
# PowerShell 7.5 - Include hidden files
Resolve-Path "C:\Users\*\.*" -Force | Select-Object -First 5
# Includes .vscode, .gitignore, .bashrc, etc.
# Find all hidden config files
Resolve-Path "C:\Projects\*\.*" -Force |
Where-Object { (Get-Item $_).Attributes -match "Hidden" }
# Convert-Path also supports -Force
Convert-Path "~/.config/*" -Force
ユースケース:
- 隠しファイルを含めるバックアップスクリプト
- 構成の検出
- セキュリティ監査
- 開発環境のセットアップ
New-FileCatalog の既定値がバージョン 2 に
FileCatalog のバージョン 2 が既定になりました。
# PowerShell 7.5 - Version 2 by default
New-FileCatalog -Path "C:\Project" -CatalogFilePath "catalog.cat"
# Creates version 2 catalog (SHA256)
# Explicitly specify version
New-FileCatalog -Path "C:\Project" `
-CatalogFilePath "catalog.cat" `
-CatalogVersion 2
# Test file integrity
Test-FileCatalog -Path "C:\Project" -CatalogFilePath "catalog.cat"
バージョンの違い:
- バージョン 1:SHA1 ハッシュ(旧式)
- バージョン 2:SHA256 ハッシュ(既定、より安全)
.NET 9 のパフォーマンス向上
大幅なパフォーマンスの向上
# PowerShell 7.5 benefits from .NET 9.0.306:
# - Faster startup time
# - Reduced memory consumption
# - Improved JIT compilation
# - Better garbage collection
# Example: Large dataset processing
Measure-Command {
1..1000000 | ForEach-Object { $_ * 2 }
}
# PowerShell 7.4: ~2.5 seconds
# PowerShell 7.5: ~1.8 seconds (28% faster)
メモリ効率
# Lower memory footprint for:
# - Large collections
# - Long-running scripts
# - Concurrent operations
# - Pipeline processing
# Monitor memory usage
[System.GC]::GetTotalMemory($false) / 1MB
# PowerShell 7.5 uses 15-20% less memory on average
PSResourceGet 1.1.1(2025 年 3 月)
最新のパッケージ管理
PSResourceGet は PowerShellGet の公式な後継であり、パフォーマンスが大幅に向上し、セキュリティも強化されています。
主な機能:
- 2 倍高速なモジュールのインストール
- セキュリティの向上 — SecretManagement と統合し、認証情報を安全に保存
- Azure Artifacts のサポート — エンタープライズ向けのプライベートフィードと統合
- エラー処理の改善 — より明確なエラーメッセージと再試行ロジック
# Install PSResourceGet (included in PowerShell 7.4+)
Install-Module -Name Microsoft.PowerShell.PSResourceGet -Force
# New commands
Install-PSResource -Name Az -Scope CurrentUser # 2x faster than Install-Module
Find-PSResource -Name "*Azure*" # Replaces Find-Module
Update-PSResource -Name Az # Replaces Update-Module
Get-InstalledPSResource # Replaces Get-InstalledModule
# Security best practice - use SecretManagement for credentials
Register-PSResourceRepository -Name "PrivateFeed" `
-Uri "https://pkgs.dev.azure.com/org/project/_packaging/feed/nuget/v3/index.json" `
-Trusted
# Retrieve credential from SecretManagement vault
$credential = Get-Secret -Name "AzureArtifactsToken" -AsPlainText
Install-PSResource -Name "MyPrivateModule" -Repository "PrivateFeed" -Credential $credential
パフォーマンスの比較:
| 操作 | PowerShellGet | PSResourceGet 1.1.1 | 改善 |
|---|---|---|---|
| モジュールのインストール | 10-15s | 5-7s | 2 倍高速 |
| モジュールの検索 | 3-5s | 1-2s | 2~3 倍高速 |
| モジュールの更新 | 12-18s | 6-9s | 2 倍高速 |
セキュリティの強化:
- スクリプトで平文の認証情報を使用しないでください
- リポジトリの認証情報の保存には SecretManagement モジュールを使用してください
- Azure DevOps Personal Access Tokens(PAT)をサポート
- Azure Artifacts と統合認証
# WRONG - plaintext credential
$cred = New-Object PSCredential("user", (ConvertTo-SecureString "password" -AsPlainText -Force))
# CORRECT - SecretManagement
Install-Module Microsoft.PowerShell.SecretManagement
Register-SecretVault -Name LocalVault -ModuleName Microsoft.PowerShell.SecretStore
Set-Secret -Name "RepoToken" -Secret "your-token"
$token = Get-Secret -Name "RepoToken" -AsPlainText
Install-PSResource -Name "Module" -Repository "Feed" -Credential $token
PowerShell 7.4 からの移行
バージョンの確認
# Current version
$PSVersionTable.PSVersion
# 7.5.4 (latest stable as of October 2025)
# .NET version
[System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription
# .NET 9.0.306
# PSResourceGet version
Get-Module Microsoft.PowerShell.PSResourceGet -ListAvailable
# Version 1.1.1 (latest as of March 2025)
7.5 向けのスクリプト更新
# Replace file-based XML serialization
# Before:
$data | Export-Clixml -Path "temp.xml"
$xml = Get-Content "temp.xml" -Raw
Remove-Item "temp.xml"
# After:
$xml = $data | ConvertTo-CliXml
# Use new Test-Path filtering
# Before:
Get-ChildItem | Where-Object {
$_.LastWriteTime -lt (Get-Date).AddDays(-30)
}
# After:
Get-ChildItem | Where-Object {
Test-Path $_.FullName -OlderThan (Get-Date).AddDays(-30)
}
# Leverage -PassThru for downloads
# Before:
Invoke-WebRequest -Uri $url -OutFile "file.zip"
$size = (Get-Item "file.zip").Length
# After:
$response = Invoke-WebRequest -Uri $url -OutFile "file.zip" -PassThru
$size = $response.RawContentLength
PowerShell 7.5 のベストプラクティス
- メモリ内のシリアル化には ConvertTo/From-CliXml を使用します:
# Serialize to clipboard
$data | ConvertTo-CliXml | Set-Clipboard
# Deserialize from clipboard
$restored = Get-Clipboard | ConvertFrom-CliXml
- Test-Path の日時フィルターを活用します:
# Clean old logs
Get-ChildItem "C:\Logs" | Where-Object {
Test-Path $_.FullName -OlderThan (Get-Date).AddDays(-90)
} | Remove-Item
- 隠しファイルの操作には -Force を使用します:
# Backup including hidden config files
Resolve-Path "~/*" -Force |
Where-Object { Test-Path $_ -OlderThan (Get-Date).AddDays(-1) } |
Copy-Item -Destination "C:\Backup\"
- ダウンロードのワークフローを簡素化します:
# Download and verify in one step
$response = Invoke-WebRequest $url -OutFile "data.zip" -PassThru
if ($response.StatusCode -eq 200) {
Expand-Archive "data.zip" -Destination "data/"
}
- 柔軟な JSON を解析します:
# Configuration files with comments
$config = Get-Content "config.jsonc" -Raw |
ConvertFrom-Json -IgnoreComments
CI/CD 統合
# GitHub Actions with PowerShell 7.5
- name: Setup PowerShell 7.5
uses: actions/setup-powershell@v1
with:
pwsh-version: '7.5.x'
- name: Run Script with 7.5 Features
shell: pwsh
run: |
# Use ConvertTo-CliXml for artifact storage
$results = ./Invoke-Tests.ps1
$results | ConvertTo-CliXml | Out-File "results.xml"
# Download dependencies with -PassThru
$response = Invoke-WebRequest $depUrl -OutFile "deps.zip" -PassThru
Write-Host "Downloaded $($response.RawContentLength) bytes"
後方互換性
PowerShell 7.5 は、7.x のスクリプトとの互換性を維持しています。
- 7.0~7.4 のすべてのスクリプトは変更せずに動作します
- 新しいパラメーターは任意で使用できます
- 既存のコマンドレットに破壊的変更はありません
- モジュールの互換性は維持されています
パフォーマンスベンチマーク
| 操作 | PowerShell 7.4 | PowerShell 7.5 | 改善 |
|---|---|---|---|
| 起動時間 | 1.2s | 0.9s | 25% 高速化 |
| 大規模なパイプライン | 2.5s | 1.8s | 28% 高速化 |
| メモリ使用量 | 120MB | 95MB | 21% 削減 |
| Web リクエスト | 450ms | 380ms | 16% 高速化 |
PowerShell 7.6 プレビュー機能
7.6 プレビュー版の詳細な解説(+= による配列結合の最適化(8~16 倍)、強化された Get-Clipboard と Get-Command、PSResourceGet 1.2.0-preview、DSC v3 リソース、PSForEach / PSWhere エイリアス、.NET 10 との統合、実験的な機能、7.5 からの破壊的変更、移行手順、7.5 と 7.6 のベンチマーク)は、references/powershell-7-6-preview.md にあります。7.6 の機能を評価または採用する際は、このリファレンスを読み込んでください。