How to check if PowerShell snap-in is already loaded before

User avatar
daniel
Site Admin
Posts: 223
Joined: Tue Jan 09, 2007 9:54 pm
Contact:

How to check if PowerShell snap-in is already loaded before

Postby daniel » Fri Apr 15, 2011 11:39 am

How to check if PowerShell snap-in is already loaded before calling Add-PSSnapin?

You should be able to do it with something like this, where you query for the Snapin but tell PowerShell not to error out if it cannot find it:

Code: Select all

if ( (Get-PSSnapin -Name <snapin> -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PsSnapin <snapin>
}


A bit dirty way to do so:

Code: Select all

Add-PSSnapin -Name <snapin> -ErrorAction SilentlyContinue

Return to “PowerShell”

Who is online

Users browsing this forum: No registered users and 1 guest