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

前端 未结 5 1416
小鲜肉
小鲜肉 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

    Surpisingly, nobody mentioned the native way for scripts to specify dependencies: the #REQUIRES -PSSnapin Microsoft.PowerShell... comment/preprocessor directive. Just the same you could require elevation with -RunAsAdministrator, modules with -Modules Module1,Module2, and a specific Runspace version.

    Read more by typing Get-Help about_requires

提交回复
热议问题