如何使用 PowerShell 檢索 MSI 包產品程式碼?
你可以使用 Get-Package 或 Get-WmiObject 命令,透過 PowerShell 在 Windows 作業系統中檢索已安裝的 MSI 打包產品程式碼。
在此示例中,我們將檢索 7-zip. 的產品程式碼。
Get-Package -Name '7-Zip 19.00 (x64 edition)' | fl *
你可以使用 tagid 或提到的屬性來篩選產品程式碼。
要使用 Get-Package 方法從遠端計算機檢索包,請使用 InvokeCommand。
Invoke-Command -ComputerName TestMachine -ScriptBlock{ (Get-Package -Name '7-Zip 19.00 (x64 edition)').TagID }
另一種檢索產品程式碼的方法是使用 WMI 方法,如下所示。
PS C:\> $product = Get-WmiObject win32_product | where{$_.name - eq "7-Zip 19.00 (x64 edition)"} PS C:\> $product.IdentifyingNumber
輸出
若要從遠端計算機獲取輸出,只需指定 -ComputerName 引數。
$product = Get-WmiObject win32_product -ComputerName TestMachine1, Testmachine2 | where{$_.name -eq "7-Zip 19.00 (x64 edition)"} $product.IdentifyingNumber
廣告