PowerShell boy and the case of the missing cmdlets!

First things first, modules in PowerShell v2.0 rule!  Next to remoting, this is my second most favorite feature in the v2.0 lineup.  And, with the CTP3 release, modules are even better, faster, stronger... After all, we can rebuild him. We have the technology... oh wait wrong topic!

Anyhow, I fully plan on diving very deep in to a number of the new features just like I did with events.  But, first I wanted to share an interesting little module quirk that I experience the other day.

Basically, I was in the process of dumping a script of mine into a module.  The script, was fairly complex, and had a bunch of code that is used to setup the execution environment.  In other words, what a module is kinda supposed to do.

Some of this environment execution code loaded up any needed types or snap-ins.  I had made an effort to swing these commands over to the newly minted modules manifest file.  But, for some reason forgot about a command that was in the script which loaded up the Quest.ActiveRoles.ADManagement snap-in.

Not a biggie, right?  Maybe not, but after I loaded up the module using the Import-Module cmdlet something very peculiar happened.  Basically, I was getting an error when trying to execute one of the functions from module.  The command that was failing was using the Get-QADObject cmdlet to retrieve some information from Active Directory.  To troubleshoot the problem, I decided to just execute the cmdlet without any of the fancy filtering ninja code, however, PowerShell kindly explained:

Get-QADObject is not recognized as a cmdlet, function, operable program, or script file.

Ah.... Ok.... I then checked to make sure the Quest.ActiveRoles.ADManagement snap-in was loaded using the Get-PSSnapin.  After all, the module I just imported should have loaded the Quest.ActiveRoles.ADManagement snap-in.  Sure enough, the snap-in was loaded.  Next, I executed the following command to see if the Quest cmdlets were available from within the PowerShell console.

Get-Command *-QAD*

Nada!  The cmdlets were not accessible.  In other words, a core concept of what a module is supposed to was now just staring back at me with an evil grin!  The cmdlets from the Quest snap-in were being isolated thanks to how modules attempt to prevent the Global scope from becoming polluted with colliding functions, variables, aliases, etc.  The only problem in this case, was that the Quest snap-in was unsuitable from within my console session, unless I first removed it, and then add it back in.

Bummer... I will need to dive a little more into this issue during another post, I do believe this might be a bigger problem.

If you like this, check out some other posts from Tyson:

Or if you want, you can also check out some of Tyson's latest publications:

Lastly, visit the Microsoft Subnet for more news, blogs, and opinions from around the Internet.  Or, sign up for the bi-weekly Microsoft newsletter(Click on News/Microsoft News Alert)

Join the Network World communities on Facebook and LinkedIn to comment on topics that are top of mind.

Copyright © 2009 IDG Communications, Inc.

SD-WAN buyers guide: Key questions to ask vendors (and yourself)