Created
October 17, 2012 11:25
-
-
Save ecampidoglio/3905035 to your computer and use it in GitHub Desktop.
Import-PSSnapin cmdlet to compensate for the shortcomings of the built-in snap-in cmdlets.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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