PowerShell: Find Installed NetApp Products

A slightly modified version of a scriptingGuy post to find NetApp software installed from a csv file (export from active directory)

$ErrorActionPreference= 'silentlycontinue'
$exedir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
#Variables
$LikePublisher = "NetApp"
######
$infile = ($exedir + "\computerlist.csv") 
Write-Host "$infile"
$computers= Import-Csv $infile
$totalComputers = $computers.count
$currentDate = (get-date -uformat "%d%m%Y")
$outfile = ($exedir + "\" + "searchpublisher-" + $LikePublisher + "_" + $currentDate + ".csv")
Write-Host "$outfile"
$checkforoutfile = Test-Path $outfile
If ($checkforoutfile){Remove-Item $outfile}
$counter1 = 0
$array = @()
foreach($pc in $computers){
    $subkeys=$NULL
    $computername=$pc.computername
    $counter1++
    Write-Progress -Activity "Processing" -Status "Processing computer $counter1 of $totalComputers"  -PercentComplete (100 * ($counter1 / $computers.count)) -ID 1
    Write-Progress "Initializing" "Connecting to the Windows System: $computername" -ParentID 1
    #Define the variable to hold the location of Currently Installed Programs
    $UninstallKey="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall" 
    #Create an instance of the Registry Object and open the HKLM base key
    $reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$computername)
    #Drill down into the Uninstall key using the OpenSubKey Method
    $regkey=$reg.OpenSubKey($UninstallKey) 
    #Retrieve an array of string that contain all the subkey names
    $subkeys=$regkey.GetSubKeyNames()
    #Open each Subkey and use GetValue Method to return the required values for each
    $counter2 = 0
    foreach($key in $subkeys){
        $counter2++
        if ($subkeys.count -eq $NULL){Write-Host "Could not connect to $computername continuing ..."}
        if (($subkeys.count -ne $NULL) -and ($key -NotLike "*KB*")){
		Write-Progress -Activity "Gathering Key information on $computername" -Status "Processing Key $key" -PercentComplete (100 * ($counter2 / $subkeys.count)) -ParentID 1
		$thisKey=$UninstallKey+"\\"+$key 
        	$thisSubKey=$reg.OpenSubKey($thisKey) 
        	$obj = New-Object PSObject
        	$obj | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $computername
        	$obj | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $($thisSubKey.GetValue("DisplayName"))
        	$obj | Add-Member -MemberType NoteProperty -Name "DisplayVersion" -Value $($thisSubKey.GetValue("DisplayVersion"))
        	$obj | Add-Member -MemberType NoteProperty -Name "InstallLocation" -Value $($thisSubKey.GetValue("InstallLocation"))
        	$obj | Add-Member -MemberType NoteProperty -Name "Publisher" -Value $($thisSubKey.GetValue("Publisher"))
        	$array += $obj
	}
    } 
}
$array | Where-Object { $_.DisplayName -and $_.Publisher -like "*$LikePublisher*"} | select ComputerName, DisplayName, DisplayVersion, Publisher | ft -auto
$array | Where-Object { $_.DisplayName -and $_.Publisher -like "*$LikePublisher*"} | select ComputerName, DisplayName, DisplayVersion, Publisher | export-csv $outfile

Leave a Reply