Skip to content

Instantly share code, notes, and snippets.

@ecampidoglio
Created October 17, 2012 11:25
Embed
What would you like to do?
Import-PSSnapin cmdlet to compensate for the shortcomings of the built-in snap-in cmdlets.
function Import-PSSnapin {
<#
.Synopsis
Adds a Windows PowerShell snap-in with the specified name to the current session.
This cmdlet will not throw an exception if the specified snap-in is already present in the session.
.Description
Helper function to safely add a Windows PowerShell snap-in with the specified name to the current session.
.Parameter Name
The name of the snap-in to import.
#>
[CmdletBinding()]
param(
[Parameter(Position=1)]
[string]$Name
)
$snapinIsNotInSession = -Not (Get-PSSnapin $Name -ErrorAction SilentlyContinue)
if ($snapinIsNotInSession) {
Add-PSSnapin $Name
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment