我希望能够在特定时间段内远程获取有关Windows VM运行时间的信息。这是我发现的脚本:
function Get-SystemUpTime {
[CmdletBinding()]
Param(
[Parameter(Position = 0, Mandatory = $false, ValueFromPipeline = $true)]
[Alias("CN")]
[String[]]$ComputerName = $Env:ComputerName,
[Parameter(Position = 1, Mandatory = $false)]
[Alias("RunAs")]
[System.Management.Automation.Credential()]$Credential = [System.Management.Automation.PSCredential]::Empty
)
Process {
foreach ($Name in $ComputerName) {
Get-WmiObject -Class Win32_PerfFormattedData_PerfOS_System -ComputerName $Name -Credential $Credential |
Select-Object @{Name="ComputerName";Expression={$_.__SERVER}},
@{Name="SystemUpTime";Expression={New-TimeSpan -Seconds $_.SystemUpTime}}
}
}
}
Get-SystemUpTime localcomputer | Sort-Object SystemUpTime
这是我写的本地脚本:
function Get-Uptime {
$os = Get-WmiObject Win32_OperatingSystem
$uptime = (Get-Date) - ($os.ConvertToDateTime($os.LastBootupTime))
$Display = "Uptime: " + $Uptime.Days + " days, " + $Uptime.Hours +
" hours, " + $Uptime.Minutes + " minutes"
Write-Output $Display
Write-Output $uptime.Hours
}
Get-Uptime
如何修改脚本以仅在可以在脚本中轻松定义的特定月份或时间段获取此信息?