I have a group of PowerShell scripts that sometimes get run together, sometimes one at a time. Each of the scripts requires that a certain snap-in be loaded.
Right n
I tried @ScottSaad's code sample but it didn't work for me. I haven't found out exactly why but the check was unreliable, sometimes succeeding and sometimes not. I found that using a Where-Object
filtering on the Name
property worked better:
if ((Get-PSSnapin | ? { $_.Name -eq $SnapinName }) -eq $null) {
Add-PSSnapin $SnapinName
}
Code courtesy of this.