-
-
Notifications
You must be signed in to change notification settings - Fork 116
Closed
Description
This is "unusual" way of object prototype creating which I often exploit.
$obj = '' | select-object <properties>
$obj.PSOBject.TypeNames.Insert(0,<FormatName>)
$obj | New-PSFormatXML -FormatType table -path <path>
You cannot call a method on a null-valued expression.
+ $Member.value.tostring().length
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
It is method .tostring() that throws error in line 195.
This happens because of property values are NULL. To avoid this a property value should be tested for $null.
It can be done like this (quick fix):
$len = if (-not $Member.value) {0} else {$Member.value.tostring().length}
$longest = $len, $member.name.length | Sort-Object | Select-Object -last 1