Coding Geekette

100% girl geek, all the time

PowerShell-Specific Providers, a Followup to 4/26

on May 3, 2011

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…


2 Responses to “PowerShell-Specific Providers, a Followup to 4/26”

  1. [...] – 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 [...]

  2. [...] 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 [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>