Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

How do I make this code run twice?

$
0
0

I found some code online that reads your UNINSTALL key in the registry and reports back what you have installed.

 

$computers = Read-Host

 

$array = @()

 

foreach($pc in $computers){

 

    $computername=$pc.computername

 

    #Define the variable to hold the location of Currently Installed Programs

 

   #$UninstallKey="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall" 

    $UninstallKey="SOFTWARE\\Wow6432Node\\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

 

    foreach($key in $subkeys){

 

        $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 } | select ComputerName, DisplayName, DisplayVersion, Publisher | ft -auto | Out-File c:\temp\$computers.txt

 

 

 

##################################################

 

There of course 2 UNINSTALL keys in bold above.  How do I make this script read both and write the contends of both to the same output file?

 

 

 

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles