我有这个脚本来检查远程服务器上是否有映射磁盘。当我在命令行中运行它时,它运行良好,从 PowerGUI 和 ISE 它运行良好,但是当我在 Windows 任务计划程序中调度它时,我收到一条邮件消息(不包括脚本的邮件发送部分),该磁盘不是映射 - 尽管磁盘已映射,但仍执行“else”。
if(Invoke-Command -ComputerName sdebt -ScriptBlock { Get-WmiObject win32_logicaldisk -ComputerName sdebt -Filter "DeviceID = 'L:'"}) {
Write-Host -ForegroundColor Green "L: is OK"} else {
Write-Host -ForegroundColor Magenta "L: is NOT OK"
$subject = "CHYBA: Disk L is not mapped"
$body += "Disk L is not mapped `r" }
谢谢你。