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

前端 未结 5 1460
小鲜肉
小鲜肉 2020-12-13 01:15

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

5条回答
  •  长情又很酷
    2020-12-13 01:54

    Scott Saads works but this seems somewhat quicker to me. I have not measured it but it seems to load just a little bit faster as it never produces an errormessage.

    $snapinAdded = Get-PSSnapin | Select-String $snapinName
    if (!$snapinAdded)
    {
        Add-PSSnapin $snapinName
    }
    

提交回复
热议问题