ArunAshokan
ArunAshokan

Reputation: 55

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

I am trying to get the product codes of all the Visual C++ 2008 Installed on my device and wrote the below code but I am stuck. Code Executes but no action takes place. Please Assist.

$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
        }

    }
} 

Upvotes: 1

Views: 521

Answers (2)

Maximilian Burszley
Maximilian Burszley

Reputation: 19664

So you're retrieving your values incorrectly and over-complicating things.

Working solution:

$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
}

Output:

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

Test key:

AuthorizedCDFPrefix :
Comments            :
Contact             :
DisplayVersion      : 9.0.30729
HelpLink            :
HelpTelephone       :
InstallDate         : 20170901
InstallLocation     :
InstallSource       : c:\14a5eb4f904aafee464a2e0ecc\
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

Upvotes: 1

Thom Schumacher
Thom Schumacher

Reputation: 1583

This should get you the Value you want:

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

Upvotes: 1

Related Questions