Functions/Get-SpecialFolders.ps1



Class SpecialFolders : System.Management.Automation.IValidateSetValuesGenerator {
    [string[]] GetValidValues() {

        $SpecialFolders = [Enum]::GetNames([Environment+SpecialFolder])

        return [string[]] $SpecialFolders

    }
}


function Get-SpecialFolders {
    [CmdletBinding()]
    param (
        [Parameter()]
        [ValidateSet([SpecialFolders])]
        [string] $SpecialFolderName
    )



    $SpecialFolders = @()

    [Enum]::GetNames([Environment+SpecialFolder]) | Sort-Object | ForEach-Object {
        $ThisSpecialFolder = [PSCustomObject]@{
            Name = $_
            PSCommand = "[Environment]::GetFolderPath(`"$_`")"
            Path = [Environment]::GetFolderPath($_)
        }
        $SpecialFolders += $ThisSpecialFolder
    }
    if ($SpecialFolderName) {
        $SpecialFolders = $SpecialFolders | Where-Object Name -EQ $SpecialFolderName
    }



    return $SpecialFolders

}