I try to run this script:
#Exit Codes
$ExitCode = @{ "Up" = 0;
"Down" = 1;
"Warning" = 2;
"Critical" = 3;
"Unknown" = 4 }
try {
Import-Module ServerManager -ErrorAction Stop
$null = Get-WindowsFeature -ErrorAction Stop
$WindowsFeatureStat = '0'
Write-Host "Statistic.WindowsFeature: $($WindowsFeatureStat)"
Write-Host "Message.WindowsFeature: Healthy"
$Status = "Up"
exit $ExitCode[$Status]
}
catch {
$WindowsFeatureStat = '1'
Write-Host "Statistic.WindowsFeature: $($WindowsFeatureStat)"
Write-Host "Message.WindowsFeature: Not Healthy: $($_.Exception.Message)"
$Status = "Critical"
exit $ExitCode[$Status]
}
But i get "Not Healthy: The specified module 'ServerManager' was not loaded because no valid module file was found in any module directory.". Locally the script is working. Any ideas?