如何从powershell报告中删除错误

时间:2017-03-30 15:59:49

标签: powershell

我创建了一个powershell脚本来远程运行图像验证,当任何服务在停止状态下找到时,这将使脚本失败。我在脚本失败时遇到错误。无论如何我都可以隐藏这些错误从报告?

+ Invoke-Command  -ScriptBlock {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], RuntimeException
    + FullyQualifiedErrorId : ScriptHalted

这是我在服务处于停止状态时失败的脚本。

$EMService = get-wmiobject win32_service | where-object {($_.Name -eq 'HP12cAgent') -or ($_.Name -eq 'HPagent12c2Agent') -or ($_.Name -eq 'HPagent10gAgent') -or ($_.Name -eq 'FarmEM10gAgent') -or ($_.Name -eq 'FarmEM11gAgent')} | format-list name | Out-String
$Servicename = $EMService.Split(":")[1].Trim()


$EMStatus1 = get-wmiobject win32_service | where-object {$_.Name -eq $Servicename} | format-list state | Out-String
$ServiceStatus = $EMStatus1.Split(":")[1].Trim()

if ($Servicename -eq $null)

{
$Servicename = "Unavailable"

}
else
{

$Servicename = "$Servicename"

}

if ($ServiceStatus -eq "Stopped")

{

throw

}

Else 

{
exit 0
}

1 个答案:

答案 0 :(得分:1)

你总是可以尝试在try / catch块中包装东西。

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Hola</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
        <div class="first">
            <div class="shadow">
                <p>Spring of Field</p>
                <p class="hidden">Spring is wonderful, unless for allergic people that die each year by.</p>
            </div>
        </div>
        <div class="second">
            <div class="shadow">
                <p>Snow world</p>
                <p class="hidden">Go in winter, after the snow doesn't exist anymore.</p>
            </div>
        </div>
    </body>
</html>