MSDN Magazine - December 2007 - (Page 77) should configure the registry entries directly. Loading the snap-in is also easy. The main cmdlets you will use are Add-PSSnapIn, RemovePSSnapIn, and Get-PSSnapIn. Not surprisingly, add-PSSnapIn adds one or more Windows PowerShell snap-ins to the current session. Remove-PSSnapIn removes snapins from the current session. And Get-PSSnapIn retrieves the Windows PowerShell snap-ins on the computer. Note that Remove-PSSnapIn Figure 10 Using the Cmdlets doesn’t actually unload the assembly. It just removes the cmdlets and providers from the lists that Windows PowerShell uses to find cmdlets and access providers. the location of the System.Management.Automation.dll and compile the assembly: New-Alias csc “${V2Framework}\csc.exe” $SMADLL = [PSObject].Assembly.Location csc /target:library IsolatedStorageSnapin.cs /r:$SMADLL Putting It All Together Once I do everything I’ve just described, I am ready to start using my new custom cmdlets. Of course, I am doing everything from the command line. First, I must compile the cmdlet and snap-in code. Remember when I said I’ll need to compile this code with a reference to System.Management.Automation.dll? This DLL can be found both in the SDK and in the GAC, but if you don’t have the SDK installed, don’t worry about it. This little script can easily create the Snap-In assembly. The first thing that I need to do is create an alias for the C# compiler, once that is established I find Now that I have compiled my assembly, I can use Installutil.exe to register my new snap-in, as shown in Figure 9. After the installation has been completed successfully, I can find the new PSSnapIn: PS> get-PSSnapIn -reg iso* Name : IsolatedStorageCmdlets PSVersion : 1.0 Description : Isolated Storage Cmdlets Then I add the snap-in to my session: PS> add-PSSnapIn IsolatedStorageCmdlets And now I can use the cmdlets, as shown in Figure 10! ■ Custom Cmdlets december2007 77
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.