Advertisement
Guest User

Untitled

a guest
Nov 8th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
  2.  
  3. #$ComputerName = [Microsoft.VisualBasic.Interaction]::InputBox("Computer Name: ", "Machine Information")
  4.  
  5. Function Get-InstalledSoftware
  6. {
  7.     Param
  8.     (
  9.         [Alias('Computer','ComputerName','HostName')]
  10.         [Parameter(ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$true,Position=1)]
  11.         [string[]]$Name = [Microsoft.VisualBasic.Interaction]::InputBox("Computer Name: ", "Machine Information")
  12.     )
  13.     Begin
  14.     {
  15.         $LMkeys = "Software\Microsoft\Windows\CurrentVersion\Uninstall","SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
  16.         $LMtype = [Microsoft.Win32.RegistryHive]::LocalMachine
  17.         $CUkeys = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
  18.         $CUtype = [Microsoft.Win32.RegistryHive]::CurrentUser
  19.        
  20.     }
  21.     Process
  22.     {
  23.         ForEach($Computer in $Name)
  24.         {
  25.             $MasterKeys = @()
  26.             If(!(Test-Connection -ComputerName $Computer -count 1 -quiet))
  27.             {
  28.                 Write-Error -Message "Unable to contact $Computer. Please verify its network connectivity and try again." -Category ObjectNotFound -TargetObject $Computer
  29.                 Break
  30.             }
  31.             $CURegKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($CUtype,$computer)
  32.             $LMRegKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($LMtype,$computer)
  33.             ForEach($Key in $LMkeys)
  34.             {
  35.                 $RegKey = $LMRegKey.OpenSubkey($key)
  36.                 If($RegKey -ne $null)
  37.                 {
  38.                     ForEach($subName in $RegKey.getsubkeynames())
  39.                     {
  40.                         foreach($sub in $RegKey.opensubkey($subName))
  41.                         {
  42.                             $MasterKeys += (New-Object PSObject -Property @{
  43.                             "ComputerName" = $Computer
  44.                             "Name" = $sub.getvalue("displayname")
  45.                             "SystemComponent" = $sub.getvalue("systemcomponent")
  46.                             "ParentKeyName" = $sub.getvalue("parentkeyname")
  47.                             "Version" = $sub.getvalue("DisplayVersion")
  48.                             "UninstallCommand" = $sub.getvalue("UninstallString")
  49.                             })
  50.                         }
  51.                     }
  52.                 }
  53.             }
  54.             ForEach($Key in $CUKeys)
  55.             {
  56.                 $RegKey = $CURegKey.OpenSubkey($Key)
  57.                 If($RegKey -ne $null)
  58.                 {
  59.                     ForEach($subName in $RegKey.getsubkeynames())
  60.                     {
  61.                         foreach($sub in $RegKey.opensubkey($subName))
  62.                         {
  63.                             $MasterKeys += (New-Object PSObject -Property @{
  64.                             "ComputerName" = $Computer
  65.                             "Name" = $sub.getvalue("displayname")
  66.                             "SystemComponent" = $sub.getvalue("systemcomponent")
  67.                             "ParentKeyName" = $sub.getvalue("parentkeyname")
  68.                             "Version" = $sub.getvalue("DisplayVersion")
  69.                             "UninstallCommand" = $sub.getvalue("UninstallString")
  70.                             })
  71.                         }
  72.                     }
  73.                 }
  74.             }
  75.             $MasterKeys = ($MasterKeys | Where {$_.Name -ne $Null -AND $_.SystemComponent -ne "1" -AND $_.ParentKeyName -eq $Null -AND ($_.Name -like "*Java*" -OR $_.Name -like "*Adobe*" -OR $_.Name -like "*Datalink*" -OR $_.Name -like "*Outlook*")} | select Name,Version | sort Name)
  76.             $MasterKeys
  77.         }
  78.     }
  79.     End
  80.     {
  81.  
  82.     }
  83. }
  84.  
  85. Get-InstalledSoftware
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement