PowerShell不会显示我的代码

时间:2015-09-11 16:09:43

标签: powershell powershell-v3.0

我是PowerShell的新手,我想知道为什么当我运行此代码时它会跳过所有内容然后直接进入暂停状态?

一旦我按下Enter键,它就不会显示任何内容并关闭窗口。

更好地解释我在这里做的事情。我正在尝试远程连接到我们网络中的服务器,并检查特定进程是否正在运行。如果它们没有运行,脚本将使它们运行。

知道我在Windows 7 64bit上的PowerShell v3中出错了吗?

$recall = Get-WmiObject win32_service -computername srv-95-obweb | Where {$_.name -eq 'Hyland Sch4'}
$sleeplab = Get-WmiObject win32_service -computername srv-95-obweb | Where {$_.name -eq 'Hyland Sch3'}

$date = Get-Date

if($recall.Status -eq 'Stopped') {
    Write-Host "Recall service is currently stopped and will be automatically started"
    Get-Service  '*Sch4' | Start-Service
    Write-Host "Recall service has been started $date"
} Else {
    if($recall.Status -eq 'Running') {
        Write-Host "Recall service is currently running"
    }
}

if($sleeplab.Status -eq 'Stopped') {
    Write-Host "Sleep Lab service is currently stopped and will be automatically started"
    Get-Service '*Sch3' | Start-Service
    Write-Host "Sleep Lab service has been started $date"
} Else {
    if($sleeplab.Status -eq 'Running') {
        Write-Host "Sleep Lab service is currently running"
    }
}

pause

1 个答案:

答案 0 :(得分:0)

第二个如果导致它是假的,所以它没有发布。也有错误的财产。制作它.State而不是.status解决了这个问题。谢谢大家的帮助