如何使用嵌套的 ForEach-Object? $_ 返回“HKCU:..”,但我想访问第二个 ForEach-Object 中的“Microsoft Teams”字符串。
@(
"Microsoft Teams",
"Microsoft Teams Meeting Add-in for Microsoft Office",
"Teams Machine-Wide Installer"
) | ForEach-Object {
"HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" | ForEach-Object {
Write-Host $_
}
}
第一个
ForEach-Object
的$_需要保存到变量中。然后,在第二个ForEach-Object
内部使用。
@(
"Microsoft Teams",
"Microsoft Teams Meeting Add-in for Microsoft Office",
"Teams Machine-Wide Installer"
) |
ForEach-Object {
$FirstItem = $_
"HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" |
ForEach-Object {
Write-Host $_
Write-Host $FirstItem
}
}