1
当我运行下面的代码时,它输出我想要的信息,但即时通讯在最终输出时遇到了问题。它显示我的UpTime为天,小时,分钟,秒。我会喜欢天和小时。我想将正常运行时间显示在列表的最后。现在出来的是Uptime,Computer,LastBootupTime。格式化我的日期时间
Function Get-UpTime
{ Param ([string[]]$servers)
Foreach ($s in $servers)
{
$os = Get-WmiObject -class win32_OperatingSystem -cn $s -ErrorAction SilentlyContinue
New-Object psobject -Property @{computer=$s;
LastBootUpTime = [Management.ManagementDateTimeConverter]::ToDateTime((Get-WmiObject - Class Win32_OperatingSystem -Computer $s | Select -Exp LastBootUpTime))
UpTime = (Get-Date) – [System.Management.ManagementDateTimeconverter]::ToDateTime((Get-WmiObject - Class Win32_OperatingSystem -Computer $s | Select -Exp LastBootUpTime))
}
}}
Get-UpTime -servers $servers|
ConvertTo-Html -As Table -body "
<h1>Server Uptime Report</h1>
The following report was run on $(get-date)" >> $path
Invoke-Item $path
所以前两行的文件输出,然后运行'GET-Uptime'和它管'的ConvertTo HTML的-As表-Properties正常运行时间,计算机,LastBootupTime'指定的属性,以及订购你想要他们。 – TheMadTechnician