Showing posts with label Win7. Show all posts
Showing posts with label Win7. Show all posts

January 26, 2010

You Can Do -Help
[Building HELP into your custom functions is a good thing! Here's a template to help you through it...]


Do you write your own Powershell functions for use in your AD or Exchange environment? Are they user friendly? Do others use them, or would you like them to? Do you add a -Help switch and display help text in your custom functions? You should! It's well worth your while to build in some HELP for a few reasons...

First, they won't be running to you to ask you syntactical questions even though you've told them six times already. Additionally, you won't be asking yourself those same questions when you try to use your awesome new function three weeks from now. Lastly, building inline help into your functions will force you to better understand how they work, as well as demonstrating your superior scripting abilities to your boss (make sure you demo the function at an upcoming staff meeting). Read on to see if your functions measure up.

Copy the code (link at end of post) and paste it into your Powershell session window to define the function called "MyTestFunction". To test the functionality, type the following at the Powershell prompt:

MyTestFunction (to show usage syntax)
MyTestFunction -Help (to display abbreviated help)
MyTestFunction -Help -Full (to display full help)
MyTestFunction SomeArgument (to simulate processing of SomeArgument)



Notes and Code for this post:
Get the shell function code here.
Although the copy code & "paste into your Powershell session" method of defining the function works for testing the function, the content should really be copied and pasted into an editor such as notepad.exe, then saved as a .ps1 script. This will retain the HELP text formatting (blank lines) that get stripped out when copy/paste into session window is used. Try it, you'll see what i mean.

This code works with Powershell v1 and v2.

Was there enough detail in this post?




.end


more...