I have a cmdlet that returns an [PSCustomObject]
. This is done 2 cmdlets deep. At every return it adds another things and then instead of returning the [PSCustomObject]
it returns an array of 3 items.
This object has string properties and at every level it adds another leading space to them.
I just want to return the [PSCustomObject]
no array. How to do this ?
The object return from the last cmdlet
$ident
LocalTime UtcTime Data
--------- ------- ----
5/6/2021 3:43:35 PM 5/6/2021 10:43:35 PM New-NodeIdentifier "4"
5/6/2021 3:43:35 PM 5/6/2021 10:43:35 PM New-NodeGenerationIdentifier "4"
$ident.Count
3
2 method deap , 2 leading spaces
"$($ident.String)"
" 4"
"$($ident[2].String)"
"4"
The functions
Function New-NodeIdentifier{
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[String]$Identifier,
[Switch]$NoCmdletEntryOutput
)
Begin{}
Process{
Start-CmdletEntry "New-NodeIdentifier `"$($Identifier)`"" -NoCmdletEntryOutput:$NoCmdletEntryOutput
#determin identifyer type
$l = $Identifier.split(".")
[double]$OutNumber = $null
$IsGen = $true
foreach( $c in $l ) {
Write-Host $c
if(-not [double]::TryParse($c,[ref]$OutNumber)) {
$IsGen = $false
}
}
# create the indentifier
if($IsGen) {
$ni = New-NodeGenerationIdentifier -Generation $Identifier
write-host "nni `"$($ni.String)`" type $($ni.GetType())"
return $ni
} else {
$ni = New-NodeHwSkuIdentifier -HwSku $Identifier
write-host "nni `"$($ni.String)`" type $($ni.GetType())"
return $ni
}
}
End{}
}
Function New-NodeGenerationIdentifier{
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[String]$Generation,
[Switch]$NoCmdletEntryOutput
)
Begin{}
Process{
Start-CmdletEntry "New-NodeGenerationIdentifier `"$($Generation)`"" -NoCmdletEntryOutput:$NoCmdletEntryOutput
$vmi = [PSCustomObject]@{
Generation ="$($Generation)"
Type ='Generation'
String ="$($Generation)"
}
write-host "nngi `"$($vmi.String)`" type $($vmi.GetType())"
return $vmi
}
End{}
}