I input a collection then I have have to loop through to make the customobject. The Names in the object are all unique. I am hoping to have PSCustomObject in a variable that I can use later.
Function Get-PSCustomObjectAsOutputType {
$services = get-service | select -First 5
[hashtable]$properties
$X = 0
foreach ($s in $services)
{
$properties += @{"Name$x" = $S.name
"Status$x" = $S.status
"Displayname$x" = $S.displayName
}
$obj = New-Object -TypeName PSCustomObject -Property $properties
$x++
}
$Obj
}
It appears that the $null happens when I assign it to a varible.
$TheTypeNeedsToBePSCustomOutputType = Get-PSCustomObjectAsOutputType
$TheTypeNeedsToBePSCustomOutputType.PSobject.TypeNames
I required that System.Object[] be PSCustomObject
PS> $TheTypeNeedsToBePSCustomOutputType.PSobject.TypeNames
System.Object[]
System.Array
System.Object
$TheTypeNeedsToBePSCustomOutputType.PSObject
The "$null" in the BaseObject is getting in my way.
BaseObject : {$null, @{Displayname3=Application Layer Gateway Service; Name4=AppIDSvc; Displayname2=AllJoyn Router
Service; Displayname0=Agent Activation Runtime_8af1b; Status0=Stopped; Status2=Stopped; Name3=ALG;
Displayname1=Intel® SGX AESM; Name2=AJRouter; Name1=AESMService; Status1=Running; Status3=Stopped;
Name0=AarSvc_8af1b; Status4=Stopped; Displayname4=Application Identity