Hoping someone can help me out with the two aspects of my script that I think is causing the most performance hindrance. Recreating the Array $Result
and using the Get-ItemProperty
on each and every key to get the required information. Is there a better way to accomplish this task?
Function Get-SoftwareList {
<#
#>
Param()
New-Variable -Force -ErrorAction SilentlyContinue -Name Result -Value @()
New-Variable -Force -ErrorAction SilentlyContinue -Name Function -Value @{}
$Function.Exclusions = (
"Security Update for Windows",
"Security Update for Microsoft",
"Update for Windows",
"Update for Microsoft",
"Hotfix for Windows",
"Update for Skype",
"Security Update for Skype"
)
If([IntPtr]::Size -eq 8){
$Function.OSArch='64-bit'
} Else{
$Function.OSArch='32-bit'
}
$Function.Registry = Get-Childitem -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
IF ($Function.OSArch -EQ "64-bit") {
$Function.Registry += Get-ChildItem -Path "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
}
ForEach ($Key in $Function.Registry) {
$Key = Get-ItemProperty -Path Registry::$Key
IF ($Key.DisplayName.length -NE 0) {
ForEach ($Exclusion in $Function.Exclusions) {
If ($Key.DisplayName.StartsWith($Exclusion) -EQ $True) {
$Skip = $True
Break
} Else {
$Skip = $False
}
}
IF ($Skip -EQ $False) {
$Result += New-Object PSObject -Property @{
DisplayName = $Key.DisplayName
Version = $Key.DisplayVersion
UninstallString = $Key.UninstallString
Publisher = $Key.Publisher
#ModifyPath = $Key.ModifyPath
InstallDate = $Key.InstallDate
}
}
}
}
Return $Result
}