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…

[...] – Alias, Function, and Variable. These can tap into the PowerShell system and help you determine what aliases, functions, and variables already exist. But then there are other providers that are there to make it easier to access data stores that are [...]
[...] Matt blogged about a basic PowerShell functions. I also have blogged in the past of some helpful functions that work with some of the PowerShell-specific providers. The code for those is fairly simple. However, functions aren’t always that simple; you can [...]