Tuesday, March 13, 2012

Month of Lunches - Day 5

Today we are discussing Adding Commands into PowerShell. PowerShell has two primary ways that these Cmdlets can be added. With the addition of these cmdlets PowerShell can handle the management of many of Microsoft's products. Some of those are Exchange, Sharepoint, SQL, the System Center suite of products, IIS, and many more. Even non-Microsoft software vendors are getting in on the action with their own modules and snap-ins, including VMWare, NetAPP, Citrix, and More. Just look up your Enterprise (and in some cases desktop) software and chances are that the manufacturer has PowerShell cmdlets or someone has created some (always test these before using them on production systems). Both make working with particular programs easier in PowerShell.

Snap-ins generally consist of DLL's, XML's, and help text. To add a Snap-in the cmdlet is Get-PSSnapin. You can also find a list of the available snap-ins, if there are any, by typing Get-PSSnapin -Registered. To add a new snap-in once it is found, Get-PSSnapin <Snap-in_Name>. Want to see what commands or PSDrives may have been added by that snap-in? Get-Command -PSSnapin <Snap-In Name> and Get-PSProvider, respectively. There are other snap-in specific commands and parameters and if you have been following along with my MOL then you should know how to find them.

The second type of extension that is covered by Don is the module. The cmdlet for adding modules is Import-Module. Modules will be automatically visible to PowerShell if they are in one of two folders. The first is your personal modules and will only be accessible if you are logged in under your profile. It is located in your "%username%\Documents\WindowsPowerShell\Modules" folder. The second is the System modules and will be accessible from any profile on the PC. It is located in the "C:\Windows\System32\WindowsPowerShell\v1.0\Modules" folder. You can also add a module manually with its full path from the import command. To get a list of available modules type Get-Module -listavailable. To import a particular module Import-Module <module_name>. You can also view the available cmdlets for a particular module, the same as with snap-ins, with Get-Command -Module <Module_Name>.

If there is a conflict with any of the modules or snap-ins then you can always remove them. To remove them the cmdlets are Remove-PSSnapin and Remove-Module. And as always read the help…

The next section of this chapter was over Server Manager via command line. There is an entire module dedicated to the adding, modifying, and removing server roles and features via the command line via its three cmdlets: Add-WindowsFeature, Get-WindowsFeature, and Remove-WindowsFeature. I find this module especially tempting to use and only wish there was an associated cmdlet that would allow the same to be done on the workstation side (alas there is not as of yet, maybe in V3?).

Now, one thing to remember about Snap-ins and Modules is that they are available only in the PowerShell session that you have open, but fear not there is a way to ensure they are available every time that you open the shell without having to import or add them. Profile Scripts! Our very first "Script". Don Covers this at length with do's and don'ts in another blog post here: "http://tinyurl.com/7pf5egw". These will allow you to configure, add modules and snap-ins, and a number of other features. I suggest you read this article and look up the number of others you can find on the same topic.

Until Tomorrow.

No comments:

Post a Comment