MSDN Magazine - December 2007 - (Page 68) James Truher Cmdlets Extend Windows PowerShell With Custom Commands s you’ve probably already discovered, Windows PowerShell™ is a powerful and flexible tool. You may not know, however, that you can extend Windows PowerShell by writing your own cmdlets. In this article, I will show you how to create your own cmdlets by writing three custom cmdlets that allow you to interact with IsolatedStorage. I chose IsolatedStorage for these samples because I have not seen any other cmdlets related to IsolatedStorage and I thought its functionality would be useful, offering a place to keep data that won’t conflict with other applications. In a nutshell, the System.IO.IsolatedStorage namespace lets you create and use isolated stores. You can read and write data that less-trusted code cannot access, preventing sensitive information from being exposed. Basically, data is only available to the current user or the assembly in which the code exists (it can also be isolated by domain). When using IsolatedStorage in these examples, I will be saving a key/value pair as strings. IsolatedStorage can store any type of data you need, but I’m sticking to strings for the purposes of this article. Remember that this article is really about cmdlets—IsolatedStorage merely provides a sample for me to work with. Also keep in mind I’m merely providing a starting point here. When you’re ready to go much deeper into creating your own custom cmdlets, be sure to check out the Windows PowerShell SDK. 68 msdnmagazine An Overview of Cmdlets When Microsoft created Windows PowerShell, it was designed to make it easy to create other command-line tools that offer the same consistency and reliability as the tools that shipped as a part of Windows PowerShell. This is in large part because the shell has a single parser for all cmdlets—this model allows the dev team to be sure that all argument parsing, error handling, and so on is done similarly for everything that a user might do. As a result, there are some pretty significant differences between This article uses the following technologies: Windows PowerShell, .NET Framework, Isolated Storage This article discusses: Windows PowerShell SDK ✥ Using the System.IO.IsolatedStorage namespace ✥ Overriding default cmdlet behavior ✥ Installing and using custom cmdlets ✥ Code download available at: msdn.microsoft.com/msdnmag/code07.aspx James Truher is currently a Program Manager in Microsoft Research Incubation working on the Response Point product. Before moving to Microsoft Research, James was a Program Manager on the Windows PowerShell team and created the Windows PowerShell scripting language with Bruce Payette. http://msdn.microsoft.com/msdnmag/code07.aspx
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.