如何获取第一个命令输出?我想取身份号码。
我尝试过以下命令:
$app = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -Like "App"}
$getNumber = $app[1]
OutPut:
IdentifyingNumber : {00000-00000-0000-000000000}
Name : App
Vendor : App
Version : 1.0.0
Caption : App, Inc.
从技术上讲,如果你放[1],它会选择数组中从[0]开始的第二个对象,所以如果你想要第一个对象,请执行$var = $app[0].IdentifyingNumber
我创建了下面的scrip,它运行得很好,谢谢大家,如果我帮助了别人,这就是脚本。
$Keys = Get-ChildItem "HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall"
foreach ($subkey in $Keys) {
if($subkey.Name -notmatch "InstallWIX_"){
Set-Location -Path $subkey.PSPath
$app1 = Get-ItemProperty -Path "." | Where-Object displayname -Match "app1"
$app2 = Get-ItemProperty -Path "." | Where-Object displayname -Match "app2"
$GUID_APP1 = $app1.PSChildName
$GUID_APP2 = $app2.PSChildName
if ($app1.Displayname -eq "APP1") {
& cmd /c msiexec.exe /x $GUID_APP1 /qn /norestart
} elseif ($app2.Displayname -eq "APP2") {
& cmd /c msiexec.exe /x $GUID_APP2 /qn /norestart
}
}
}