I have a function called Get-InstalledApps
that connects to all computers listed with the -computers
parameter, which accepts input via the pipeline.
There are two problems when piping computer names to the function:
(a) I have a CSV file I can pass to it but it parses the value like this: @{computername=HOSTNAME}
instead of just HOSTNAME
.
(b) When piping from Get-ADComputer -Filter *
instead, it's only grabbing the last computer name passed.
Here's my function:
function Get-InstalledApps {
Param (
[CmdletBinding()]
[Parameter(ValueFromPipeline=$true)]
[Alias('name')]
[string[]]$computers = $env:COMPUTERNAME
)
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"
}
}
}
Update: This issue has been resolved. Here is the gist for those who want it:
https://gist.github.com/TylerJWhit/f596c307cf87540842281a8a20149f9a