# $PSCustomObject not displaying correctly

**URL:** <https://forums.powershell.org/t/pscustomobject-not-displaying-correctly/10756>\
**Category:** PowerShell Help\
**Created:** [June 4, 2018, 1:34pm UTC](https://forums.powershell.org/t/pscustomobject-not-displaying-correctly/10756 "2018-06-04T13:34:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![necronomicon](https://avatars.discourse-cdn.com/v4/letter/n/eada6e/32.png) [@necronomicon](https://forums.powershell.org/u/necronomicon)\
**Post date:** [June 4, 2018, 1:34pm UTC](https://forums.powershell.org/t/pscustomobject-not-displaying-correctly/10756/1 "2018-06-04T13:34:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [June 4, 2018, 4:11pm UTC](https://forums.powershell.org/t/pscustomobject-not-displaying-correctly/10756/2 "2018-06-04T16:11:28Z")

</div>

Using your code as is, why not just to this…

```
Get-InstalledApps -computername labpc01 | Format-Table -AutoSize

Computer is online.

Computer DisplayName DisplayVersion Publisher PSComputerName RunspaceId               
-------- ----------- -------------- --------- -------------- ----------               
         Mozilla Firefox 59.0.2 (x64 en-US) 59.0.2 Mozilla labpc01 9a04ae9d-5a92-4467-bf0...
         Mozilla Maintenance Service 59.0.2 Mozilla labpc01 9a04ae9d-5a92-4467-bf0...
```

PoSH defaults to list view if you results exceed a specific column count. IF you want a table you have to reduce the count or force it using the format cmdlets.

---

<div class="post-metadata">

**Author:** ![necronomicon](https://avatars.discourse-cdn.com/v4/letter/n/eada6e/32.png) [@necronomicon](https://forums.powershell.org/u/necronomicon)\
**Post date:** [June 4, 2018, 4:22pm UTC](https://forums.powershell.org/t/pscustomobject-not-displaying-correctly/10756/3 "2018-06-04T16:22:31Z")

</div>

Hello:

What I ended up doing a while ago was adding the Format-Table to:

```
$objs | Where-Object { $_.DisplayName } | Format-Table
```

Absolutely worked; your suggestion and column count advisement was spot on. Thanks for your help.

-Brandon

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:35pm UTC](https://forums.powershell.org/t/pscustomobject-not-displaying-correctly/10756/4 "2024-05-16T20:35:00Z")

</div>

Closed on May 16, 2024, 8:35pm UTC


