0
votes

I have read alot of the posts and have pulled alot of great info. But i am still having an issue getting a version number to pull from the registry. I found this code to get an IE version, and that seems to work just fine.

$array =@() 
$keyname = 'SOFTWARE\\Microsoft\\Internet Explorer' 
$computernames = Get-Content C:\scripts\test_names1.csv 
foreach ($server in $computernames) 
{ 
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $server) 
$key = $reg.OpenSubkey($keyname) 
$value = $key.GetValue('svcVersion') 
 $obj = New-Object PSObject 

    $obj | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $server 

    $obj | Add-Member -MemberType NoteProperty -Name "IEVersion" -Value $value 

    $array += $obj  


} 

$array | select ComputerName,IEVersion | export-csv C:\scripts\test1-IE_Version.csv

But when i modify it to try to get a Google Chrome version it fails with the

**Get-ItemProperty : Cannot bind argument to parameter 'Path' because it is null.**

Here is what I modified to try to get the Chrome version.

$array =@()
$keyname = '\\SOFTWARE\\Wow6432Node\\Google\\Update\\clients\\{8A69D345-D564-463c-AFF1-A69D9E530F96}'
$computernames = Get-Content C:\scripts\test_names.csv
foreach ($server in $computernames)
{
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $server)
$regkey = $reg.OpenSubKey('SOFTWARE\\Wow6432Node\\Google\\Update\\clients\\{8A69D345-D564-463c-AFF1-A69D9E530F96}')
$value = (Get-ItemProperty -Path $regkey -Name pv).pv
$obj = New-Object PSObject 

    $obj | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $server 
    $obj | Add-Member -MemberType NoteProperty -Name "Installed" -Value $installed 
    $obj | Add-Member -MemberType NoteProperty -Name "ChromeVersion" -Value $value
    $array += $obj  
}

$array | select ComputerName,Installed,ChromeVersion | export-csv C:\scripts\1222016_Chrome_Version.csv

I had to change the $keyname and $value variables due to the original edit throwing even more errors. I am completely new at powershell so be easy on me.

Thanks in advance.

-S

2
Would recommend Import-Csv over Get-Content for CSV files.Benjamin Hubbard
What debugging have you tried? Usually when you get an error due to a null value it's because something that you expect to exist does not exist.Benjamin Hubbard
When i step through it it dumps at the "You cannot call a method on a null-valued expression. At C:\scripts\Get_Chrome_Version.ps1:8 char:1 + $value = $regkey.GetValue('pv')"SeanDu
Which I can see, the $regkey var doesn't look like it has a value. When it runs it has one but when it goes to grab the var $regkey the $reg looks empty?SeanDu

2 Answers

0
votes

The following works for me, which is basically the same as your IE code:

$keyname = 'SOFTWARE\\Wow6432Node\\Google\\Update\\clients\\{8A69D345-D564-463c-AFF1-A69D9E530F96}'
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $server)
$regkey = $reg.OpenSubKey($keyname)
$value = $regkey.GetValue('pv')
0
votes

If I understand your question, you are asking about how to tell what programs are installed on a computer, and also what the IE version is on a computer, which is a special case.

First, if an app is "installed" and appears in the Programs and Features list, then you can use the Get-InstalledApp.ps1 script I wrote from this article to see what applications are installed:

Windows IT Pro: Auditing 32-Bit and 64-Bit Applications with PowerShell

However, since Internet Explorer is an OS component and is not "installed" as a typical program, I wrote a different script to find the IE version:

Get-IEVersion.ps1