Functions/Scripting/Remove-NullProperties.ps1
function Remove-NullProperties { [cmdletbinding()] param ( # Input Object [parameter(Mandatory=$true,ValueFromPipeline=$True)] [psobject] $InputObject ) process { # Instantiate a new empty Hash Table (Key-value Map) $objHT = [ordered]@{} # Loop over all input-object properties. foreach ($P in $InputObject.psobject.properties) { # If a property is non-$null, add it to the HT if ($InputObject.$($P.Name) -ne $null) {$objHT.add($P.Name,$P.Value)} } # Create the the output object [pscustomobject]($objHT) } } |