0

我是 PowerShell 新手,需要帮助。以下是检查 BizTalk 中主机实例状态的标准脚本。

我有两个任务: 1. 邮寄脚本的输出。2.调度PS脚本。

$servers = (".")

#This function checks the status of the host instances on a BizTalk server ($Server).
function checkhostinstancestatusstarted ($server)
{
#gets all host instances on the server. Isolated (hosttype = 2) or disabled hosts are excluded .
    $hostinstances = get-wmiobject MSBTS_HostInstance -namespace 'root\MicrosoftBizTalkServer' | where {$_.runningserver -match $server -AND $_.hosttype -ne "2" -and $_.IsDisabled -ne "True"}
    write-host "Checking the state of all host instances on the server $server`:"

    foreach ($hostinstance in $hostinstances)
    {
        $HostInstanceName = $HostInstance.hostname

#Checks the host instance state
        if ($HostInstance.ServiceState -eq 1)
        {
            write-host "$HostInstanceName`: Stopped."
        }
        elseif ($HostInstance.ServiceState -eq 2)
        {
            write-host "$HostInstanceName`: Start pending."
        }
        elseif ($HostInstance.ServiceState -eq 3)
        {
            write-host "$HostInstanceName`: Stop pending."
        }
        elseif ($HostInstance.ServiceState -eq 4)
        {
            write-host "$HostInstanceName`: Started."
        }
        elseif ($HostInstance.ServiceState -eq 5)
        {
            write-host "$HostInstanceName`: Continue pending."
        }
        elseif ($HostInstance.ServiceState -eq 6)
        {
            write-host "$HostInstanceName`: Pause pending."
        }
        elseif ($HostInstance.ServiceState -eq 7)
        {
            write-host "$HostInstanceName`: Paused."
        }
        elseif ($HostInstance.ServiceState -eq 8)
        {
            write-host "$HostInstanceName`: Unknown."
        } 
    }
write-host `n  

        }

foreach ($server in $servers)
{
    checkhostinstancestatusstarted $server
}
4

1 回答 1

0

看起来您的 PowerShell 脚本仍然需要更多代码才能将输出保存到文件中。一旦你让那部分工作,如果你有一个 Microsoft Exchange 服务器,这里是我们每天早上使用的一个脚本,通过电子邮件将日志文件的输出发送给我们。Exchange 的好处是它有一个名为“pickup”的文件夹,它将以电子邮件的形式发送一个名为“*.eml”的格式正确的文本文件。将此代码放入一个 vbscript 文件(即,将其命名为“EmailScript.vbs”或其他),然后通过单击开始>管理工具>任务计划程序并指向 * .vbs 文件。为了安排 Powershell 脚本本身,我在 Google 上找到了几篇关于此的文章:

http://community.spiceworks.com/how_to/show/17736-run-powershell-scripts-from-task-scheduler

http://blogs.technet.com/b/heyscriptingguy/archive/2012/08/11/weekend-scripter-use-the-windows-task-scheduler-to-run-a-windows-powershell-script.aspx

'First retrieve the contents of the log file
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile("C:\logfile", 1)
content = file.ReadAll
file.close

msg = "To: jdoe@company.com"
msg = msg & chr(13) & chr(10)
msg = msg & "From: server@server.com"
msg = msg & chr(13) & chr(10)
msg = msg & "Subject: powershell results"
msg = msg & chr(13) & chr(10) & chr(13) & chr(10) & content

Set f = fso.OpenTextFile("\\ServerName\c$\program files\microsoft\exchange server\transportroles\pickup\powershell.eml",2, True)
f.Write msg
f.Close
Set f = Nothing
Set fso = Nothing
于 2013-03-27T19:22:48.953 回答