【发布时间】:2017-11-29 19:16:48
【问题描述】:
我有一个在 MW 后运行的重新启动检查脚本,我需要它来提取最后一次重新启动以验证服务器是否已重新启动,目前它们会提取所有重新启动历史记录。以下是我的脚本:
$DHCP = (Get-Content -Path "\\termserv\d$\SERVER1\SERVER2\Scripts\morescripts\DHCPServers.txt")
foreach ($Server in $DHCP) {
Get-Service -ComputerName $Server -DisplayName "DHCP Server" |
ConvertTo-Html -Title "PScomputername" -Body "<H3> SERVER2 Uptime Report </H3> " -Property PSComputername >> \\termserv\d$\SERVER1\SERVER2\Server3\SERVER2.html
Get-Service -ComputerName $Server -DisplayName "DHCP Server" |
ConvertTo-Html -Property MachineName,Status,ServiceName |
foreach {
if ($_ -like "*<td>Running</td>*") {
$_ -replace "<tr>", "<tr bgcolor=green>"
} elseif ($_ -like "*<td>Stopped</td>*") {
$_ -replace "<tr>", "<tr bgcolor=red>"
} else {
$_
}
} >> \\termserv\d$\SERVER1\SERVER2\Server3\SERVER2.html
Get-WmiObject win32_operatingsystem -ComputerName $Server |
Select PSComputername, @{n='BootTime';e={$_.ConvertToDateTime($_.LastBootupTime)}} |
ConvertTo-Html -Property PSComputerName,BootTime >> \\termserv\d$\SERVER1\SERVER2\Server3\SERVER2.html
ConvertTo-Html -Property PSComputerName,Installedon,Description,caption >> \\termserv\d$\SERVER1\SERVER2\Server3\SERVER2.html
}
$Print = (Get-Content -Path "\\termserv\d$\SERVER1\SERVER2\Scripts\morescripts\PrintServers.txt")
foreach ($Server in $Print) {
Get-Service -ComputerName $Server -DisplayName "Print Spooler" |
ConvertTo-Html -Property MachineName,Status,ServiceName |
foreach {
if ($_ -like "*<td>Running</td>*") {
$_ -replace "<tr>", "<tr bgcolor=green>"
} elseif ($_ -like "*<td>Stopped</td>*") {
$_ -replace "<tr>", "<tr bgcolor=red>"
} else {
$_
}
} >> \\termserv\d$\SERVER1\SERVER2\Server3\SERVER2.html
Get-WmiObject win32_operatingsystem -ComputerName $Server |
Select PSComputername, @{n='BootTime';e={$_.ConvertToDateTime($_.LastBootupTime)}} |
ConvertTo-Html -Property PSComputerName,BootTime >> \\termserv\d$\SERVER1\SERVER2\Server3\SERVER2.html
ConvertTo-Html -Property PSComputerName,Installedon,Description,caption >> \\termserv\d$\SERVER1\SERVER2\Server3\SERVER2.html
}
【问题讨论】:
-
我已尽我所能重新格式化以提高可读性。
标签: powershell reboot