A snap-in is essentially a collection of cmdlets. For example, running the Get-Pssnapin cmdlet shows the snap-ins provided with the basic shell as shown below:
PS C:\> get-pssnapin Name : Microsoft.PowerShell.Core PSVersion : 1.0 Description : This Windows PowerShell snap-in contains Windows PowerShell management ... Name : Microsoft.PowerShell.Host PSVersion : 1.0 Description : This Windows PowerShell snap-in contains cmdlets used by the Windows Po... Name : Microsoft.PowerShell.Management PSVersion : 1.0 Description : This Windows PowerShell snap-in contains management cmdlets used to man... Name : Microsoft.PowerShell.Security PSVersion : 1.0 Description : This Windows PowerShell snap-in contains cmdlets to manage Windows Powe... Name : Microsoft.PowerShell.Utility PSVersion : 1.0 Description : This Windows PowerShell snap-in contains utility Cmdlets used to manipu...
You can add the -pssnapin parameter to the Get-Command cmdlet to see which cmdlets are in a particular snap-in. Below is a partial list for the Microsoft.PowerShell.Utility snap-in:
PS C:\> get-command -pssnapin microsoft.powershell.utility CommandType Name Definition ----------- ---- ---------- Cmdlet Add-Member Add-Member [-M Cmdlet Clear-Variable Clear-Variable Cmdlet Compare-Object Compare-Object Cmdlet ConvertTo-Html ConvertTo-Html Cmdlet Export-Alias Export-Alias [ Cmdlet Export-Clixml Export-Clixml Cmdlet Export-Csv Export-Csv [-P Cmdlet Format-Custom Format-Custom Cmdlet Format-List Format-List [[ Cmdlet Format-Table Format-Table [ Cmdlet Format-Wide Format-Wide [[ Cmdlet Get-Alias Get-Alias [[-N Cmdlet Get-Culture Get-Culture [- Cmdlet Get-Date Get-Date [[-Da Cmdlet Get-Host Get-Host [-Ver Cmdlet Get-Member Get-Member [[- Cmdlet Get-TraceSource Get-TraceSourc
As you'll learn later in this chapter, you can make custom versions of PowerShell that include just the snap-ins you want, which essentially creates task-specific versions of the shell.
But wait a moment. What will happen if you create a script that relies on a particular snap-in being present, and share that script with an administrator who doesn't have that snap-in? The answer is that the script won't work. One way you can help remember which snap-ins a script requires, is to use a self-documenting feature in PowerShell. For example, you can add something like the following to your script:
#requires -PSSnapIn Microsoft.PowerShell.Utility
Of course, you don't need to specify this for the core snap-ins because they're always present, so there's no way to create a shell without them. However, if you're using nonstandard snap-ins, it's a good idea to add #requires to your script.