powershell-2025-changes について
2025年に記載された PowerShell の変更を追う管理者や開発者向けの移行リファレンスです。削除項目、モジュール移行、セキュリティ指針、レガシー依存の確認方法を扱います。
主な機能
- 01PowerShell 2.0 削除の案内
- 02MSOnline と AzureAD の移行経路
- 03WMIC とパッケージ管理の移行
- 04JSON スキーマと PSSnapin の変更
- 05セキュリティと移行のチェックリスト
活用シーン
- 01スクリプトの廃止依存を監査
- 02ID コマンドを Microsoft.Graph に移行
- 03WMIC と PowerShellGet の使用を置換
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ josiahsiegel/ claude-plugin-marketplace --skill powershell-2025-changesインストール後、Claude Code で/powershell-2025-changesを入力して読み込まれたか確認します。
詳細
PowerShell 2025年の破壊的変更と移行
2025年におけるPowerShellの重大な変更、非推奨化、移行方法について説明します。
PowerShell 2.0の削除(2025年8月~9月)
削除されるもの
PowerShell 2.0は、以下から完全に削除されました。
- Windows 11 バージョン24H2(2025年8月)
- Windows Server 2025(2025年9月)
理由: セキュリティの強化、攻撃対象領域の縮小、レガシーコードの整理
移行方法
# Check if PowerShell 2.0 is installed
Get-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2Root
# If you still need PowerShell 2.0 (NOT RECOMMENDED)
# - Use older Windows versions
# - Use Windows containers with older base images
# - Upgrade scripts to PowerShell 5.1 or 7+
# Recommended: Migrate to PowerShell 7.5+
winget install Microsoft.PowerShell
必要な対応: すべてのスクリプトを監査し、PowerShellの呼び出しから -Version 2.0 パラメーターを削除してください。
MSOnlineおよびAzureADモジュールの廃止
廃止のスケジュール
| モジュール | 動作停止 | 廃止完了 |
|---|---|---|
| MSOnline | 2025年5月下旬 | 2025年5月31日 |
| AzureAD | 2025年3月30日 | 2025年7月1日以降 |
重要: これらのモジュールは非推奨になるだけでなく、完全に動作しなくなります。
移行方法
MSOnline/AzureADからMicrosoft.Graphへの移行:
# OLD (MSOnline) - STOPS WORKING MAY 2025
Connect-MsolService
Get-MsolUser
Set-MsolUser -UserPrincipalName "[email protected]" -UsageLocation "US"
# NEW (Microsoft.Graph 2.32.0)
Connect-MgGraph -Scopes "User.ReadWrite.All"
Get-MgUser
Update-MgUser -UserId "[email protected]" -UsageLocation "US"
# OLD (AzureAD) - STOPS WORKING MARCH 2025
Connect-AzureAD
Get-AzureADUser
New-AzureADUser -DisplayName "John Doe" -UserPrincipalName "[email protected]"
# NEW (Microsoft.Graph 2.32.0)
Connect-MgGraph -Scopes "User.ReadWrite.All"
Get-MgUser
New-MgUser -DisplayName "John Doe" -UserPrincipalName "[email protected]"
代替手段: Microsoft Entra PowerShellモジュール(AzureADの後継)を使用します。
Install-Module -Name Microsoft.Graph.Entra -Scope CurrentUser
Connect-Entra
Get-EntraUser
よく使われるコマンドの対応表
| MSOnline/AzureAD | Microsoft.Graph | 備考 |
|---|---|---|
Get-MsolUser / Get-AzureADUser | Get-MgUser | User.Read.Allスコープが必要 |
Get-MsolGroup / Get-AzureADGroup | Get-MgGroup | Group.Read.Allスコープが必要 |
Get-MsolDevice / Get-AzureADDevice | Get-MgDevice | Device.Read.Allスコープが必要 |
Connect-MsolService / Connect-AzureAD | Connect-MgGraph | スコープベースのアクセス許可 |
WMICの削除(Windows 11 25H2)
削除されるもの
Windows 11 25H2以降へのアップグレード後、**Windows Management Instrumentation Command-line(WMIC)**ツールが削除されます。
移行方法
WMICからPowerShellのWMI/CIMへの移行:
# OLD (WMIC) - REMOVED
wmic process list brief
wmic os get caption
# NEW (PowerShell CIM)
Get-CimInstance -ClassName Win32_Process | Select-Object Name, ProcessId, CommandLine
Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object Caption, Version
# For detailed process info
Get-Process | Format-Table Name, Id, CPU, WorkingSet -AutoSize
# For system info
Get-ComputerInfo | Select-Object WindowsProductName, WindowsVersion
PowerShellGetからPSResourceGetへの移行
最新のパッケージ管理(2025年)
PSResourceGetはPowerShellGetの公式な後継であり、2倍高速で、現在も積極的に開発されています。
# Install PSResourceGet (ships with PowerShell 7.4+)
Install-Module -Name Microsoft.PowerShell.PSResourceGet -Force
# New commands (PSResourceGet)
Install-PSResource -Name Az -Scope CurrentUser # Replaces Install-Module
Find-PSResource -Name "*Azure*" # Replaces Find-Module
Update-PSResource -Name Az # Replaces Update-Module
Get-InstalledPSResource # Replaces Get-InstalledModule
# Compatibility layer available for legacy scripts
# Your old Install-Module commands still work but call PSResourceGet internally
パフォーマンスの比較:
- PowerShellGet:モジュールのインストールに10~15秒
- PSResourceGet:モジュールのインストールに5~7秒(2倍高速)
Test-Jsonのスキーマ変更
破壊的変更(PowerShell 7.4以降)
Test-Jsonは、Newtonsoft.Json.Schemaの代わりにJsonSchema.NETを使用するようになりました。
影響: Draft 4のJSONスキーマはサポートされなくなりました。
# OLD (Draft 4 schema) - NO LONGER SUPPORTED
$schema = @"
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object"
}
"@
Test-Json -Json $json -Schema $schema # FAILS in PowerShell 7.4+
# NEW (Draft 6+ schema) - SUPPORTED
$schema = @"
{
"$schema": "http://json-schema.org/draft-06/schema#",
"type": "object"
}
"@
Test-Json -Json $json -Schema $schema # WORKS
#Requires -PSSnapinの削除
破壊的変更(PowerShell 7.4以降)
#Requires -PSSnapinに関連するすべてのコードが削除されました。
# OLD (PowerShell 5.1 and earlier)
#Requires -PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
# NEW (Use modules instead)
#Requires -Modules ExchangeOnlineManagement
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline
セキュリティの強化(2025年の標準)
Just Enough Administration(JEA)
本番環境では、JEAがセキュリティ要件になりました。
# Create JEA session configuration
New-PSSessionConfigurationFile -SessionType RestrictedRemoteServer `
-Path "C:\JEA\RestrictedAdmin.pssc" `
-VisibleCmdlets @{
Name = 'Restart-Service'
Parameters = @{ Name = 'Name'; ValidateSet = 'Spooler' }
} `
-LanguageMode NoLanguage
# Register JEA endpoint
Register-PSSessionConfiguration -Name RestrictedAdmin `
-Path "C:\JEA\RestrictedAdmin.pssc" `
-Force
# Connect with limited privileges
Enter-PSSession -ComputerName Server01 -ConfigurationName RestrictedAdmin
Windows Defender Application Control(WDAC)
PowerShellスクリプトの制御には、AppLockerの代わりにWDACを使用します。
# Create WDAC policy for PowerShell scripts
New-CIPolicy -FilePath "C:\WDAC\PowerShellPolicy.xml" `
-ScanPath "C:\Scripts" `
-Level FilePublisher `
-Fallback Hash
# Convert to binary and deploy
ConvertFrom-CIPolicy -XmlFilePath "C:\WDAC\PowerShellPolicy.xml" `
-BinaryFilePath "C:\Windows\System32\CodeIntegrity\SIPolicy.p7b"
制約付き言語モード
管理者権限のないすべてのユーザーに対し、制約付き言語モードの使用が推奨されるようになりました。
# Check current language mode
$ExecutionContext.SessionState.LanguageMode
# Output: FullLanguage (admin) or ConstrainedLanguage (standard user)
# Set system-wide constrained language mode via Group Policy or Environment Variable
# Set HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\__PSLockdownPolicy = 4
PowerShell 7.6のプレビュー機能
現在の状況(2025年10月)
PowerShell 7.6.0 Preview 5が利用可能です(.NET 9.0.101をベースにビルド)。
新機能:
- PSRedirectToVariable:変数へのリダイレクトに対応
- モジュール名の変更:ThreadJob → Microsoft.PowerShell.ThreadJob
- PSResourceGet 1.1.0:パフォーマンスの向上とAzure Artifactsのサポート
# Check PowerShell version
$PSVersionTable.PSVersion
# 7.5.4 (stable) or 7.6.0-preview.5
# .NET version
[System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription
# .NET 9.0.101
移行チェックリスト
直ちに必要な対応(2025年)
- MSOnline/AzureADの使用状況を監査する - 2025年5月までにMicrosoft.Graph 2.32.0へ移行する
- PowerShell 2.0への参照を削除する - PowerShell 7.5以降にアップグレードする
- WMICコマンドを置き換える - Get-CimInstance/Get-Processを使用する
- JSONスキーマを更新する - Draft 4からDraft 6以降に移行する
- PSSnapinの要件を削除する - モジュールに変換する
- PSResourceGetを導入する - より高速で最新のパッケージ管理を実現する
- JEAを導入する - 本番環境でロールベースのアクセス制御を行う
- WDACを有効にする - PowerShellスクリプトのアプリケーション制御を行う
- 制約付き言語モードをテストする - 管理者権限のないユーザー向けに使用する
推奨されるアクション
- PowerShell 7.5.4 にアップグレード - .NET 9 を搭載した最新の安定版です
- Az 14.5.0 を採用 - ゾーン冗長性に対応した最新の Azure モジュールです
- Microsoft.Graph 2.32.0 を使用 - 継続的にメンテナンスされている Graph SDK です
- スクリプトブロックのログ記録を有効化 - セキュリティ監査に役立ちます
- コード署名を導入 - 本番環境のスクリプト向けです
- Azure Key Vault を使用 - 認証情報を管理できます
移行のテスト
# Test for deprecated module usage
Get-Module MSOnline, AzureAD -ListAvailable
# If found, plan migration immediately
# Test for PowerShell 2.0 dependencies
Get-Content "script.ps1" | Select-String -Pattern "powershell.exe -Version 2"
# If found, remove version parameter
# Test for WMIC usage
Get-ChildItem -Path "C:\Scripts" -Recurse -Filter "*.ps1" |
Select-String -Pattern "wmic" |
Select-Object Path, Line
# Verify PowerShell version compatibility
#Requires -Version 7.0
Test-Path $PSCommandPath # Ensures script is PowerShell 7+
リソース
最終更新日: 2025年10月