Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

LocalHost converting the LastBoot time of RemoteHost into LocalTime

$
0
0
The Uptime script showing correct LastBoot time on local server however showing incorrect LastBoot time of Remote server. LocalHost converting the LastBoot time or RemoteHost into LocalTime

Function get-Uptime {
Param([string]$computername=$env:computername)
Process{
if ($_) {$computername=$_}
    $Computerobj = "" | select ComputerName, Uptime, LastReboot, TimeZone
    $WOS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $ComputerName
    $LastBootUpTime = $WOS.ConvertToDateTime($WOS.LastBootUpTime)
    $Uptime = (Get-Date) - $LastBootUpTime
    $day =$Uptime.Days
    $hour =$Uptime.Hours
    $minute =$Uptime.Minutes
    $second = $Uptime.Seconds
    $timz = Get-WmiObject -Class win32_timezone -ComputerName $computername |Select -ExpandProperty Caption
$Computerobj.ComputerName = $computername
$Computerobj.Uptime = "$day Days $hour Hours $minute Min $second Sec"
$Computerobj.LastReboot = $LastBootUpTime
$Computerobj.TimeZone = $timz
$Computerobj    
}
}


*****LocalHost****** LastReboot Correctly displayed***
ComputerName : LocalHost
Uptime       : 72 Days 12 Hours 56 Min 14 Sec
LastReboot   : 1/29/2014 3:18:46 AM
TimeZone     : (UTC-05:00) Eastern Time (US & Canada)

*****RemoteHost****** LastReboot incorrecly displayed***
ComputerName : RemoteHost
Uptime       : 73 Days 12 Hours 47 Min 52 Sec
LastReboot   : 1/28/2014 3:27:55 AM
TimeZone     : (UTC-08:00) Pacific Time (US & Canada)

*****Actual LastReboot time on RemoteHost******

ComputerName : RemoteHost
Uptime       : 73 Days 12 Hours 47 Min 52 Sec
LastReboot   : 1/28/2014 12:27:55 AM
TimeZone     : (UTC-08:00) Pacific Time (US & Canada)

Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>