Learn about Windows PowerShell
Summary: Learn how to use the BSonPoSH Windows PowerShell module to simplify Active Directory management tasks.
Hey, Scripting Guy! I am wondering if there are any modules that can help me with routine, daily administration tasks. I really hate to re-invent the wheel, so if you can point the way to a nice, juicy module, I would be most appreciative.
Microsoft Scripting Guy Ed Wilson here. Well, the days are counting down to the Scripting Wife and my road trip. We will be in Columbus, Ohio, for the Central Ohio PowerShell Users Group meeting on July 21, 2011. They have announced a location for this meeting, so make sure you check it out. On Saturday July 23, 2011, we will be at the SQL Saturday in Wheeling, West Virginia, so there is plenty of fun this week. Check out the Scripting Guys Community page for upcoming live and virtual events.
OL, speaking of community, I think I have just the thing. Microsoft Windows PowerShell MVP Brandon Shell (a.k.a. BSonPoSH) has created a really cool module named, appropriately enough, the BSonPoSH module. Not all community-developed modules are on CodePlex. Some are on MSDN’s Code Gallery, some are on the Scripting Guys Script Repository, some are on PoshCode, and others are stored on individuals’ blogs. This plethora of locations is simply endemic of the richness of the community. Brandon has links to his module, which is stored on the MSDN Code Gallery, from his blog and CodePlex.
After I download the .zip file, unblock it in Explorer, expand the files, and copy them to the appropriate location, I can begin to work with the module using standard module techniques.
For more information about working with modules refer to articles referenced by the modules tag on the Hey, Scripting Guy! Blog.
One thing that might be a bit confusing is that there are multiple modules contained in the BSonPoSH module. After I have installed the module, I like to use the Get-Module command with the listavailable switch. When I do, I see several modules that are supplied by the BSonPoSH module. The command and associated output are shown here.
The module that is supplied by the manifest is the root module, and the one that loads the other modules and commands. To load the root module, I use the Load-Module cmdlet and provide it with the name of the module to load. Normally, I use wildcard characters when loading modules, but because all the modules begin with the letters BS, I decide to use the full module name to ensure that the proper module loads. The command is shown here:
By default, no output appears when importing a module. If for some reason I decide I need to see exactly what is happening, I can use the verbose switch. The command and associated output are shown in the following figure.
I like to use the Get-Command cmdlet (gcm is an alias) to see which commands are available from the newly imported module. With the BSonPosh module, I have lots of commands to choose from. I decide to send the output to the Format-Table cmdlet (ft is an alias) so that I have a nice list of the commands.
PS C:\> gcm -Module bsonposh | ft name, commandtype -AutoSize
If I want to see what kinds of things I can get using the module, I modify the previous command and tell it to give me only commands including the verb Get. This revised command and associated output are shown here.
PS C:\> gcm -Module bsonposh -verb get | ft name, commandtype -AutoSize
Some of the commands are rather mundane, such as the Get-MotherBoard command:
PS C:\> Get-MotherBoard
ComputerName Manufacturer Name Version SerialNumber
NEWMRED Intel Corporation DP67DE AAG10217-205 BTDE111000Z6
But there are some really cool commands in this module. For example, one of the things that is still a pain to figure out using the GUI tools is who the FSMO role owners are. This information is easily obtained using the Get-FSMO command. The command and associated output are shown here:
PS C:\> Get-FSMO
ComputerName Role Domain
dc1.iammred.net PDCMaster iammred.net
dc1.iammred.net RIDMaster iammred.net
dc1.iammred.net InfrastructureMaster iammred.net
dc1.iammred.net SchemaMaster iammred.net
dc1.iammred.net DomainNamingMaster iammred.net
The commands allow me to use the pipeline and format the output in a different manner. For example, I can pipe the output from the Get-ComputerDomainInfo command to the Format-List (fl is the alias) cmdlet and use the asterisk wildcard character to choose all the properties. This command and associated output are shown here:
PS C:\> Get-ComputerDomainInfo | fl *
DCSite : Default-First-Site-Name
Domain : IAMMRED
Forest : iammred.net
ComputerName : NEWMRED
CurrentDC : \\DC3
ClientSite : Default-First-Site-Name
OL, that is all there is to using the BSonPoSH module. Community Week will continue tomorrow.
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at email@example.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson, Microsoft Scripting Guy
I don't know if you get notified if people comment on something or not, but I posted on something from 2008. I just want to make sure you see it. Thanks!
@Diddle Yes, there is a notification. So you do not like Okra :-)
a superb module in deed ... good to know that we can find it somewhere in the small world!
And that's exactly what I mentioned in a comment before;
You said: "This plethora of locations is simply endemic of the richness of the community"
I say: "I want a library of powershell modules that is always the first place to look at"
.. like the CPAM ... the library of perl modules!