在Windows Server 2012中使用PowerShell添加和刪除Windows角色和功能非常方便,但是在windows 8.1上啟用和禁用Windows選項卻略顯雞肋。
比如Get-WindowsOptionalFeature獲取當前所有的Windows功能選項:
代碼如下:
PS> Get-WindowsOptionalFeature -Online | select * -First 1
FeatureName : Microsoft-Hyper-V-All
State : Enabled
Path :
Online : True
WinPath :
SysDrivePath :
RestartNeeded : False
LogPath : I:/Windows/Logs/DISM/dism.log
ScratchDirectory :
LogLevel : WarningsInfo
Microsoft-Hyper-V-All到底是什么?是不是下圖中的Windows功能對話框中的Hyper-V,還是Hyper-V管理平臺。如果能有一個英文的FeatureName和下圖中本地化名稱對應就好了。
PowerShell獲取Windows功能選項
幸好WMI中的Win32_OptionalFeature可以做到這一點:
代碼如下:
Get-WmiObject -Class Win32_OptionalFeature |
Select Name,Caption |
ConvertTo-Html
輸出結果為: