我是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
}
答案 0 :(得分:0)
看起来您的PowerShell脚本仍需要更多代码才能将输出转换为文件。一旦你有了这个部分,如果你有一个Microsoft Exchange Server,这是我们每天早上用来通过电子邮件向我们发送日志文件输出的脚本。关于Exchange的好处是它有一个名为“pickup”的文件夹,它将一个名为“* .eml”的格式正确的文本文件作为电子邮件发送。 将此代码放入vbscript文件(即将其命名为“EmailScript.vbs”或其他任何内容),然后通过单击“开始”>“管理工具”>“任务计划程序”并指向*,将运行的vbscript计划为服务器上的每日计划任务。 .vbs文件。 为了安排Powershell脚本本身,我在Google上发现了几篇关于它的文章:
http://community.spiceworks.com/how_to/show/17736-run-powershell-scripts-from-task-scheduler
'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