-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-SoftwareList.ps1
More file actions
89 lines (88 loc) · 3.22 KB
/
Get-SoftwareList.ps1
File metadata and controls
89 lines (88 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
function Get-SoftwareList
{
# This shit is disgusting, what was I thinking?
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[string]$ComputerName
)
$colSoftwareReport = [System.Collections.Generic.List[System.Object]]::new()
$strStatus = ''
if (Test-Connection -ComputerName $ComputerName -Count 1 -Quiet)
{
try
{
$RemoteSoftware32Registry = ([Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', "$ComputerName")).OpenSubKey('Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\')
$RemoteSoftware64Registry = ([Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', "$ComputerName")).OpenSubKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\')
}
catch
{
$SoftwareReturnObj = [pscustomobject]@{
Status = "Unable to access remote registry"
Results = $null
}
return $SoftwareReturnObj
}
$colSoftwareRaw = [System.Collections.Generic.List[System.Object]]::new()
foreach ($KeyName in ($RemoteSoftware32Registry).GetSubKeyNames())
{
$TempObject = [pscustomobject]@{
'DistinguishedName' = $null
'DisplayName' = $null
'DisplayVersion' = $null
'Publisher' = $null
'InstallLocation' = $null
'InstallDate' = $null
'UninstallString' = $null
}
$Reg32Key = $RemoteSoftware32Registry.OpenSubKey("$KeyName")
$TempObject.DistinguishedName = $KeyName
$TempObject.DisplayName = $Reg32Key.GetValue('DisplayName')
$TempObject.DisplayVersion = $Reg32Key.GetValue('DisplayVersion')
$TempObject.Publisher = $Reg32Key.GetValue('Publisher')
$TempObject.InstallLocation = $Reg32Key.GetValue('InstallLocation')
$TempObject.UninstallString = $Reg32Key.GetValue('UninstallString')
$TempObject.InstallDate = $Reg32Key.GetValue('InstallDate').Insert(6,'-').Insert(4,'-')
if ($TempObject.DisplayName -eq $null -or $TempObject.DisplayName -eq '')
{
continue
}
$colSoftwareRaw.Add($TempObject)
}
foreach ($KeyName in ($RemoteSoftware64Registry).GetSubKeyNames())
{
$TempObject = [pscustomobject]@{
'DistinguishedName' = $null
'DisplayName' = $null
'DisplayVersion' = $null
'Publisher' = $null
'InstallLocation' = $null
'InstallDate' = $null
'UninstallString' = $null
}
$Reg32Key = $RemoteSoftware64Registry.OpenSubKey("$KeyName")
$TempObject.DistinguishedName = $KeyName
$TempObject.DisplayName = $Reg32Key.GetValue('DisplayName')
$TempObject.DisplayVersion = $Reg32Key.GetValue('DisplayVersion')
$TempObject.Publisher = $Reg32Key.GetValue('Publisher')
$TempObject.InstallLocation = $Reg32Key.GetValue('InstallLocation')
$TempObject.UninstallString = $Reg32Key.GetValue('UninstallString')
$TempObject.InstallDate = $Reg32Key.GetValue('InstallDate').Insert(6, '-').Insert(4, '-')
if ($null -eq $TempObject.DisplayName -or $TempObject.DisplayName -eq '')
{
continue
}
$colSoftwareRaw.Add($TempObject)
}
$SoftwareReturnObj = [pscustomobject]@{
Status = 'Complete'
Results = $colSoftwareRaw | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate, InstallLocation, UninstallString | Sort-Object DisplayName
}
return $SoftwareReturnObj
}
else
{
Write-Error "Unable to connect to computer [$computername]"
}
}