Using Windows PowerShell as an IT Pro – Part 4
In my last post I talked about the Get-help cmdlet and how it gives you detailed information on how the cmdlets are used. Now I will talk about snap-ins.
A Windows PowerShell snap-in is a Microsoft .NET Framework assembly that contains Windows PowerShell providers and/or cmdlets. Windows PowerShell includes a set of basic snap-ins, but you can extend the power and value of Windows PowerShell by adding snap-ins that contain providers and cmdlets that you create or get from others.
When you add a snap-in, the cmdlets and providers that it contains are immediately available for use in the current session, but the change affects only the current session.
To add the snap-in to all future sessions, save it in your Windows PowerShell profile. You can also use the Export-Console cmdlet to save the snap-in names to a console file and then use it in future sessions. You can even save multiple console files, each with a different set of snap-ins.
Windows PowerShell includes a set of Windows PowerShell snap-ins that contain the built-in providers and cmdlets. You can get a list of snapins in the current Windows PowerShell session by using the Get-PSSnapin cmdlet.
Get-PSSnapin
If you wanted to get a list of the cmdlets in a snap-in you would use the Get-Command cmdlet with the PSSnapin parameter.
Get-Command -PSSnapin Microsoft.PowerShell.Security

The built-in snap-ins are registered in the system and added to the default session when you start Windows PowerShell. You can also add other registered snap-ins to the current Windows PowerShell session by using the Add-PSSnapin cmdlet.
After the command is completed, the providers and cmdlets in the snap-in are available in the session. However, they are available only in the current session unless you save them. To use a snap-in in future Windows PowerShell sessions, add the Add-PSSnapin command to your Windows PowerShell profile, or export the snap-in names to a console file.
Add-PSSnapin Microsoft.Windows.AD
In my next Post we will look talk about how to retain a snap-in in Windows PowerShell so that you don’t have to add it each time you need it.
No comments:
Post a Comment