Functions/Get-SpecialFolders.ps1



function Get-SpecialFolders {
    [CmdletBinding()]
    param (
        [Parameter()] [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

}


$scriptblock = {
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
    $o = [Enum]::GetNames([Environment+SpecialFolder]) | Sort-Object | Where-Object { $_ -like "$wordToComplete*" }
    $o | ForEach-Object {
        if ($_ -match " ") {
            "'$_'"
        } else {
            $_
        }
    }
}
Register-ArgumentCompleter -CommandName Get-SpecialFolders -ParameterName SpecialFolderName -ScriptBlock $scriptblock