使用 Powershell 从注册表中获取安装的 C++ 2008 的产品代码

Get Product Codes of C++ 2008 Installed from registry using Powershell

我试图获取我设备上安装的所有 Visual C++ 2008 的产品代码并编写了以下代码,但我被卡住了。代码执行但没有任何动作发生。请协助。

$log      = "C:\VC2008.log"
$regkey = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |  Select-Object DisplayName)
$RegKey.PSObject.Properties |  ForEach-Object {
    If($_.Name -like '*DisplayName*')
    {
        If ($_.value -like 'Microsoft Visual C++ 2008')
        {
            "$date [INFO]`t $regkey.PSChildname found in Registry !!! " | Out-File $log -append
        }

    }
} 

这应该能为您提供所需的价值:

    (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* ).displayname | Where-object{$_ -like 'Microsoft visual c++ 2008*'}

所以你在错误地检索你的值并且使事情过于复杂。

工作解决方案:

$Log    = 'C:\VC2008.log'
$RegKey = Get-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
     Where-Object { $_.DisplayName -like '*Microsoft Visual C++ 2008*' }
If ($RegKey)
{
    "$(Get-Date) [INFO]`t $($RegKey.PSChildName) found in registry!" |
        Out-File -FilePath $Log -Append
}

输出:

12/20/2017 11:12:51 AM [INFO] {8220EEFE-38CD-377E-8595-13398D740ACE} found in registry!

测试键:

AuthorizedCDFPrefix :
Comments            :
Contact             :
DisplayVersion      : 9.0.30729
HelpLink            :
HelpTelephone       :
InstallDate         : 20170901
InstallLocation     :
InstallSource       : c:a5eb4f904aafee464a2e0ecc\
ModifyPath          : MsiExec.exe /X{8220EEFE-38CD-377E-8595-13398D740ACE}
NoModify            : 1
NoRepair            : 1
Publisher           : Microsoft Corporation
Readme              :
Size                :
EstimatedSize       : 1136
UninstallString     : MsiExec.exe /X{8220EEFE-38CD-377E-8595-13398D740ACE}
URLInfoAbout        :
URLUpdateInfo       :
VersionMajor        : 9
VersionMinor        : 0
WindowsInstaller    : 1
Version             : 151025673
Language            : 1033
DisplayName         : Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.17
sEstimatedSize2     : 13596
PSPath              : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\{8220EEFE-38CD-377E-8595-13398D740ACE}
PSParentPath        : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall
PSChildName         : {8220EEFE-38CD-377E-8595-13398D740ACE}
PSProvider          : Microsoft.PowerShell.Core\Registry