With the number of PowerShell snap-ins that are available continuing to grow steadily, I’ve noticed more and more that people are looking for ways to determine if a snap-in was properly registered, whether snap-in changes are properly showing up in the PowerShell console, and answers to other general snap-in troubleshooting questions (note, a PowerShell snap-in is also referred to as a PSSnapin within the PowerShell console). Fortunately, as is the nature with many things in PowerShell, there are a number of one-liners that we can use to gather information about snap-ins or to diagnose and troubleshoot snap-in problems. I’ll list each one with the question that it was designed to answer below.
What snap-ins come with PowerShell?
Get-PSSnapin `
| Where-Object { $_.IsDefault -eq $true }
What third-party snap-ins do I have on this system?
Get-PSSnapin -Registered
Which of the third-party snap-ins are already added to my current PowerShell session?
Get-PSSnapin `
| Where-Object { $_.IsDefault -eq $false }
Which of the third-party snap-ins are not added to my current PowerShell session?
Get-PSSnapin -Registered `
| Where-Object { (Get-PSSnapin $_.Name -ErrorAction SilentlyContinue) -eq $null }
How can I see all snap-ins and identify which ones come with PowerShell, which ones are third-party, which ones are added to my current PowerShell session and which ones are not (i.e. how do I put all of this information together)?
(Get-PSSnapin | Where-Object {$_.IsDefault -eq $true}) + (Get-PSSnapin -Registered) `
| Add-Member -Force -Name IsAdded -MemberType ScriptProperty -Value {(Get-PSSnapin $this.Name -ErrorAction SilentlyContinue) -ne $null} {} -PassThru `
| Format-List -Property Name,IsDefault,IsAdded,PSVersion,Description
I’m having general issues when using a third-party snap-in (cmdlets I’m trying to use aren’t found, changes made in a new version aren’t showing up in PowerShell, etc). The snapin is called ProblematicSnapin. How can I find out detailed information about the snap-in itself so that I can verify the information about the snap-in in PowerShell and troubleshoot the issues? Note that for this one-liner you must replace “ProblematicSnapin” with the name of the third-party snap-in you are using.
Get-PSSnapin -Registered -Name ProblematicSnapin `
| Add-Member -Force -Name IsAdded -MemberType ScriptProperty -Value {(Get-PSSnapin $this.Name -ErrorAction SilentlyContinue) -ne $null} {} -PassThru `
| Format-List -Property *
What cmdlets are provided by a snap-in? Note that for this one-liner you must replace “SnapinName” with the name of the snap-in you are inquiring about. Also note that this only works for default snap-ins and snap-ins that have been added to the current PowerShell session.
Get-PSSnapin -Name SnapinName `
| ForEach-Object { Get-Command -PSSnapin $_ }
Hopefully these one-liners will help you get answers to your PSSnapin related questions.
Enjoy!
Kirk out.
Technorati Tags: PowerShell, PoSh, Poshoholic, Get-PSSnapin, oneliner, one-liner
[…] How do I add all of my installed PowerShell snapins to the current session so that I can use their cmdlets too? Get-PSSnapin -Registered | ForEach-Object { if ((Get-PSSnapin $_.Name -ErrorAction SilentlyContinue) -eq $null) { Add-PSSnapin $_.Name } } (Note: More useful one-liners using Get-PSSnapin can be found here.) […]