function Get-SetDifference { <# .SYNOPSIS Returns List $a minus the entries of List $b #> [CmdletBinding()] Param ( [Parameter(Mandatory=$true)] [AllowNull()] [object]$a, [Parameter(Mandatory=$true)] [AllowNull()] [object]$b ) if(!$a) { return $null } if(!$b) { return $a } $results = @(); $map = @{}; foreach($key in $b) { $map.Add($key, '1') } foreach($key in $a) { if(!($map.ContainsKey($key))) { $results += $key } } return $results }