I want to be able to remotely fetch information about the Windows VM uptime in specific period of time. This is the script I found:
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
This is the local script I wrote:
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
How can I modify script to fetch this information only for specific month or time period, that I can easily define in script?