graph.refined.ps1
<#PSScriptInfo .VERSION 1.0 .GUID 1f67b411-363a-4386-96dd-a3e3ce21d3e8 .AUTHOR Daniel Bradley .DESCRIPTION Removed null values for Microsoft Graph PowerShell command responses .COMPANYNAME .COPYRIGHT .TAGS .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES .PRIVATEDATA #> function Refine { [CmdletBinding()] param( [Parameter(Mandatory, Position = 0, ValueFromPipeline)] [object] $InputObject, [switch] $limit ) foreach ($object in $InputObject) { if ($object -is [string] -or $object.GetType().IsPrimitive) { $object return } $NewObj = @{ } $PropertyList = $object.PSObject.Properties | Where-Object { $null -ne $_.Value } foreach ($Property in $PropertyList) { If ($limit) { if (($property.TypeNameOfValue -eq "System.String") -or ($property.TypeNameOfValue -eq "System.String[]")){ $NewObj[$Property.Name] = $Property.Value } } Else { $NewObj[$Property.Name] = $Property.Value } } [PSCustomObject]$NewObj } } |