If you were sitting in my presentation last Tuesday, you may have caught my comment on some of the PowerShell-specific providers (Variable, Alias, Function) and how I haven’t really seen much use of them. While watching Allen White present on PowerShell and Policy Management in SQL 2008, I had a thought about this. I thought of a use for these providers What if you wanted to check to see if an alias existed before creating it? Same question for variables and functions…

We have the Test-Path cmdlet, so why not use Test-Path with these providers to see if the items exist before creating them?

While these are fairly primitive, they can work:

function Test-Alias($aliasname){
    return Test-Path "alias:$aliasname"
}

function Test-Function($functionname){
    return Test-Path "function:$functionname"
}

function Test-Variable($variablename){
    return Test-Path "variable:$variablename"
}

Oh the random PowerShell thoughts that zip by…