Files
management-scripts/Get-InstalledSoftware.ps1
T

54 lines
2.6 KiB
PowerShell
Raw Normal View History

## Specify output file to write data to
$FILE = "${Env:UserProfile}\Desktop\InstalledSoftware.csv"
## Clear content of output file
If ( Test-Path $FILE ) { Clear-Content -Path $FILE -Force }
## Write the headers to the output file
Write-LineToFile -Path $FILE -Line "Name,Publisher,Version,InstallDate,EstimatedSize(MB),UninstallString,ModifyPath"
ForEach ( $item in $(Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall','HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall') ) {
If ( Test-ItemProperty -Path $item.PSPath -Name DisplayName ) {
$DisplayName = Get-ItemPropertyValue -Path $item.PSPath -Name DisplayName
$DisplayName = $DisplayName -replace ",", " "
} Else { $DisplayName = "" }
If ( Test-ItemProperty -Path $item.PSPath -Name DisplayVersion ) {
$DisplayVersion = Get-ItemPropertyValue -Path $item.PSPath -Name DisplayVersion
$DisplayVersion = $DisplayVersion -replace ",", " "
} Else { $DisplayVersion = "" }
If ( Test-ItemProperty -Path $item.PSPath -Name EstimatedSize ) {
$EstimatedSize = Get-ItemPropertyValue -Path $item.PSPath -Name EstimatedSize
$EstimatedSize = $EstimatedSize -replace ",", " "
$size = [int]$EstimatedSize
$size = [Math]::Ceiling($size / 1024)
$EstimatedSize = [string]$size
} Else { $EstimatedSize = "" }
If ( Test-ItemProperty -Path $item.PSPath -Name InstallDate ) {
$InstallDate = Get-ItemPropertyValue -Path $item.PSPath -Name InstallDate
$InstallDate = $InstallDate -replace ",", " "
} Else { $InstallDate = "" }
If ( Test-ItemProperty -Path $item.PSPath -Name Publisher ) {
$Publisher = Get-ItemPropertyValue -Path $item.PSPath -Name Publisher
$Publisher = $Publisher -replace ",", " "
} Else { $Publisher = "" }
If ( Test-ItemProperty -Path $item.PSPath -Name UninstallString ) {
$UninstallString = Get-ItemPropertyValue -Path $item.PSPath -Name UninstallString
$UninstallString = $UninstallString -replace ",", " "
} Else { $UninstallString = "" }
If ( Test-ItemProperty -Path $item.PSPath -Name ModifyPath ) {
$ModifyPath = Get-ItemPropertyValue -Path $item.PSPath -Name ModifyPath
$ModifyPath = $ModifyPath -replace ",", " "
} Else { $ModifyPath = "" }
## Write installed software to output file only if it has a name, otherwise discard
If ( $DisplayName -ne "" ) {
$content = "${DisplayName},${Publisher},${DisplayVersion},${InstallDate},${EstimatedSize},${UninstallString},${ModifyPath}"
Write-LineToFile -Path $FILE -Line $content
}
}