我有一个工作代码,它在一组服务器中搜索service1,在另一组服务器中搜索service2。下面是代码。我将附加到文本文件并将其作为附件发送。现在我打算以表格格式在邮件正文中编写这个输出。
$date = Get-Date -format "dd-MMM-yyyy-hh-mm"
$AllTestServers = {server1.company.com server2.company.com server3.company.com server4.company.com server5.company.com server6.company.com server7.company.com server8.company.com server9.company.com server10.company.com}
$AllProdServers = {prod1.company.com prod2.company.com prod3.company.com prod4.company.com prod5.company.com prod6.company.com prod7.company.com prod8.company.com prod9.company.com prod10.company.com }
$Testservers = $AllTestServers -Split(" ")
For ($i=0; $i -lt $Testservers.Count; $i++)
{
$status = Get-Service -Name <serviceName1> -computername $$Testservers[$i] | Select -ExpandProperty Status
Write-output `r`n $Testservers[$i] ": $status" | Out-File C:\Test\TestServers_$date.txt -Append - -NoNewline
}
$Prodservers = $AllProdServers -Split(" ")
For ($i=0; $i -lt $Prodservers.Count; $i++)
{
$status = Get-Service -Name <serviceName2> -computername $Prodservers[$i] | Select -ExpandProperty Status
Write-output `r`n $Prodservers[$i] ": $status" | Out-File C:\Test\Prodservers_$date.txt -Append - -NoNewline
}
任何帮助?