Greetings:
This script is designed to look in the registry for installed applications on remote-PC’s. In its current state the script executes without issue, but the output is formatted in rows and I am looking for columns with rows. I am confident the issue is with the $PSCustomObject construct; when I remove the Invoke-Command the script formats output as intended. This is my first real try at using the $PSCustomObject accelerator type so hopefully I am not too far off…
function Get-InstalledApps {#start of function [CmdletBinding()] param ( [parameter(Mandatory = $true,ValueFromPipeline =$true)] [Alias("CN")] [string] $computername ) $testconn = Test-Connection -ComputerName $computername -Quiet if ($testconn) { Write-Host "Computer is online." } else { Write-Host "Computer is offline." } # Start of Invoke-Command scriptblock content $scriptblockcontent = { $objs = @() $RegKey = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" $InstalledAppsInfos = Get-ItemProperty -Path $RegKey Foreach($InstalledAppsInfo in $InstalledAppsInfos) { $Obj = [PSCustomObject]@{Computer=$ComputerName; DisplayName = $InstalledAppsInfo.DisplayName; DisplayVersion = $InstalledAppsInfo.DisplayVersion; Publisher = $InstalledAppsInfo.Publisher} $objs += $Obj } $objs | Where-Object { $_.DisplayName } } # End of scriptblock content Invoke-Command -ComputerName $computername -ScriptBlock $scriptblockcontent } #End of Function
As always, if there’s a more sensible (best practices) way to approach what I am trying to accomplish, I am “all ears.”
Thanks.