Bir modülün olup olmadığını kontrol etmek için aşağıdakileri denedim:
try {
Import-Module SomeModule
Write-Host "Module exists"
}
catch {
Write-Host "Module does not exist"
}
Çıktı:
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
Bir hata alıyorum, ancak bir istisna atılmıyor, bu nedenle Module exists, olmamasına rağmen sonunda görüyoruz SomeModule.
Sisteme bir PowerShell modülünün takılı olup olmadığını tespit etmenin iyi bir yolu (tercihen bir hata oluşturmadan) var mı?