-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathRemove-NullValues.ps1
More file actions
33 lines (27 loc) · 874 Bytes
/
Remove-NullValues.ps1
File metadata and controls
33 lines (27 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<#
.SYNOPSIS
Removes dictionary entries with null vaules.
.INPUTS
System.Collections.IDictionary to remove nulls from.
.OUTPUTS
System.Collections.IDictionary with null-valued entries removed.
.FUNCTIONALITY
Dictionary
.EXAMPLE
@{ a = 1; b = $null; c = 3 } |Remove-NullValues.ps1
Name Value
---- -----
c 3
a 1
#>
#Requires -Version 3
[CmdletBinding()][OutputType([Collections.IDictionary])] Param(
# A dictionary to remove the nulls from.
[Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)][Collections.IDictionary] $InputObject
)
Process
{
$nullvaluekeys = $InputObject.Keys |Where-Object {$InputObject[$_] -eq $null}
$nullvaluekeys |ForEach-Object {$InputObject.Remove($_)}
return $InputObject
}