Public/Get-FatCsvAsArray.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Function Get-FatCsvAsArray {
    param(
        [parameter(Mandatory = $true)] [string]$csvPath,
        [parameter(Mandatory = $false)] [switch]$RecurseOnly
    )
    $csvPath = Resolve-Path $csvPath
    Test-FatCsvHeaders -csvPath $csvPath
    $myCsv = Import-Csv $csvPath
    If ($PSBoundParameters.ContainsKey('RecurseOnly')) {
        $myCsv = $myCsv | Where-Object -Property Recurse -eq "True" | Group-Object Container, Folder, Recurse | ForEach-Object { [pscustomobject]@{Container = $_.Name.split(",")[0].Trim(); Folder = $_.Name.split(",")[1].Trim(); Recurse = $_.Name.split(",")[2].Trim(); Items = $_.Group } }
    }
    else {
        $myCsv = $myCsv | Where-Object -Property Recurse -in "True", "False" | Group-Object Container, Folder, Recurse | ForEach-Object { [pscustomobject]@{Container = $_.Name.split(",")[0].Trim(); Folder = $_.Name.split(",")[1].Trim(); Recurse = $_.Name.split(",")[2].Trim(); Items = $_.Group } }
    }
    return $myCsv
}