Last active
December 7, 2019 16:02
-
-
Save TylerJWhit/f596c307cf87540842281a8a20149f9a to your computer and use it in GitHub Desktop.
List all applications in Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Version: 0.5 | |
# Date: 2019-01-30 | |
# File Name: Get-InstalledApps | |
# Author: TylerJWhit | |
# Notes: | |
# The following commands may be of help: | |
# | |
# Run against every computer in domain. | |
# Get-ADComputer -Filter * | Select-Object -ExpandProperty Name | Get-InstalledApps | |
# | |
# Run against CSV (replace path with location of file and ensure A1 says 'computername': | |
# Get-InstalledApps -computers (Import-Csv -Path C:\Computers.csv | Select-Object -ExpandProperty computername) | |
# | |
# Run against computers listed in command: | |
# Get-InstalledApps -computers HOSTNAMEA,HOSTNAMEB | |
function Get-InstalledApps { | |
Param ( | |
[CmdletBinding()] | |
[Parameter(ValueFromPipeline=$true)] | |
[Alias('name')] # Helps with 'Select-Object -ExpandProperty Name' | |
[string[]]$computers = $env:COMPUTERNAME | |
) | |
process { | |
foreach($computer in $computers){ | |
write-verbose -verbose -message "`nStarting scan on $computer" | |
Invoke-Command -Computername $computer -ErrorAction SilentlyContinue -ErrorVariable InvokeError -Scriptblock { | |
$installPaths = @('HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall','HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall') | |
Get-ChildItem -Path $installPaths | Get-ItemProperty | Sort-Object -Property DisplayName | Select-Object -Property DisplayName, DisplayVersion, Publisher, UninstallString, Version | |
} | |
if ($invokeerror){ | |
Write-Warning "Could not communicate with $computer" | |
} # if ($invokeerror) | |
} # foreach($computer in $computers) | |
} # process | |
} # function Get-InstalledApps |
Get-InstalledApps -computers (Import-Csv -Path C:\computername.csv | Select-Object -ExpandProperty computername)
fixed the issue. I was missing -ExpandProperty
My last issue is iteration of the Piped values instead of simply running against the last value.
Last piece of the puzzle: missing the process bracket.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Select Name statement works with the Alias, but it's only trying the last entry piped to it. The Import-Csv keeps parsing the name like this: @{computername=hostname}