모듈이 있는지 확인하기 위해 다음을 시도했습니다.
try {
Import-Module SomeModule
Write-Host "Module exists"
}
catch {
Write-Host "Module does not exist"
}
출력은 다음과 같습니다.
Import-Module : The specified module 'SomeModule' was not loaded because no valid module file was found in any module directory.
At D:\keytalk\Software\Client\TestProjects\Export\test.ps1:2 char:5
+ Import-Module SomeModule
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (SomeModule:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Module exists
오류가 발생하지만 예외가 발생 하지 않으므로 존재하지 않지만 Module exists결국 볼 수 SomeModule있습니다.
PowerShell 모듈이 시스템에 설치되어 있는지 감지하는 좋은 방법 (가급적이면 오류를 생성하지 않음)이 있습니까?