Tag Archives: parameters

Get Parameter

As I continue to work on the 2nd edition of Managing Active Directory with Windows PowerShell: TFM, I find situations where I need a tool to get information out of Windows PowerShell. For example, the cmdlets in the Microsoft Active Directory module have a lot of parameters and I wanted to know some specifics. Now I could simply keep reading the full cmdlet help, but that gets kind of tedious. Instead I remembered I can use the Get-Command cmdlet to dig into the details.

For example, here are the parameters for Get-Service.

The value, System.Management.Automation.ParameterMetadata is intriguing. The output is a dictionary object so I can check just a single parameter.

I can even take it a step further and get attribute information.

Now that I know where to go and how to get what I need, I can write a function to retrieve parameters for a given cmdlet or function.

The function has comment based help and examples so be sure to take a look. Otherwise the function is pretty straight forward. I use it with an alias, gpa.

I’m sure it needs a few tweaks so let me know what works and what doesn’t.  You can download Get-Parameter.ps1 here.

Bool vs Switch

I have to say I’m generally impressed with the quality of submissions to this year’s Scripting Games. But there is a recurring concept that some people are using and I think there’s a better way. Some contestants are defining function or script parameters as booleans. But I believe they really should be using the [switch] type. Let me show you why.

Continue reading Bool vs Switch

More Fun with Get-NumberedContent

As much fun as the original Get-NumberedContent function was after using it for awhile I realized I had imposed some limitations. I also realized it needed to be more flexible. What if someone wanted to specify a different color or use a different comment character such as a ; in an ini file? I also thought of a few more useful features, so I went back to my script editor and came up with a PowerShell v2.0 version of the function.

Continue reading More Fun with Get-NumberedContent