Dyota's blog

.NET alternatives for PowerShell commandlets

[System.IO.File]::ReadAllText($FilePath)
Get-Content $FilePath -Raw

Select unique by n properties

$seen = [System.Collections.Generic.HashSet[string]]::new([StringComparer]::OrdinalIgnoreCase)

$unique = foreach ($row in $data) {
    $key = "$($row.Project)|$($row.'Bookable Resource')|$($row.Start)|$($row.Finish)|$($row.'Position Name')|$($row.Role)"
    if ($seen.Add($key)) {
        $row
    }
}
$data = $unique

exclude groups

$removeKeys = [System.Collections.Generic.HashSet[string]]::new([StringComparer]::OrdinalIgnoreCase)
foreach ($record in $remove) {
    $key = "$($record.Project)|$($record.'Bookable Resource')|$($record.Start)|$($record.Finish)|$($record.'Position Name')|$($record.Role)"
    [void]$removeKeys.Add($key)
}

# Filter out matching records
$data = $data | 
    ? {
        $key = "$($_.Project)|$($_.'Bookable Resource')|$($_.Start)|$($_.Finish)|$($_.'Position Name')|$($_.Role)"
        -not $removeKeys.Contains($key)
    }

$data.Count