所以我有以下代码输出安装的所有功能和角色:
Import-Module ServerManager
$Arr = Get-WindowsFeature | Where-Object {$_.Installed -match “True”} | Select-Object -Property Name
$loopCount = $Arr.Count
For($i=0; $i -le $loopCount; $i++) {
Write-Host $Arr[$i]
}
Run Code Online (Sandbox Code Playgroud)
但是,输出是:
@{Name=Backup-Features}
@{Name=Backup}
@{Name=Backup-Tools}
Run Code Online (Sandbox Code Playgroud)
我怎么能摆脱@和{}?
用Select -ExpandProperty Name而不是Select -Property Name
或者,我建议使用Foreach-Object而不是C风格的循环.
Import-Module ServerManager
Get-WindowsFeature |
Where-Object {$_.Installed -match “True”} |
Select-Object -ExpandProperty Name |
Write-Host
Run Code Online (Sandbox Code Playgroud)
要么
Import-Module ServerManager
Get-WindowsFeature |
Where-Object {$_.Installed -match “True”} |
ForEach-Object {
$_.Name | Write-Host
}
Run Code Online (Sandbox Code Playgroud)
小智 6
一个漂亮的衬垫怎么样?
Get-WindowsFeature | ? {$_.Installed -match “True”} | Select -exp Name
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29458 次 |
| 最近记录: |