tags:

views:

410

answers:

4

I have a PC on remote connected by network, but it occasionally crashes or is restarted by remote users. After the restart, some services and applications have to be in running status. So I would like to find out the reboot as soon as possible. I think PS may be a good choice with some scripts so that I could make remote call to get the last reboot timestamp information.

Is there any way to get a remote Windows XP last reboot timestamp by using PowerShell 2.0(its remoting feature)?

+1  A: 

The uptime of the computer in seconds is available in the "System Up Time" performance counter. Though that's probably overkill.

Obviously, for services the easiest thing is to just set their start mode to "Automatic" but if you have other things that need to be running, the easiest way to do that is via the Windows task scheduler: you can set up a schedule that runs when the computer starts up.

Dean Harding
That's true by setting automatic service or schedule tasks. However, the reboot might be caused by network or some other hardware issues, and they may cause services or app not being able to run. That's why I need to get last reboot timestamp and check its changes.
David.Chu.ca
You can still use the performance counter then, as a "safety net", I suppose. Performance counters can be read remotely.
Dean Harding
+3  A: 

You can do this via WMI:

$wmi = Get-WmiObject -Class Win32_OperatingSystem -Computer "RemoteMachine"
$wmi.ConvertToDateTime($wmi.LastBootUpTime)
fatcat1111
how about to get the info from a remote PC? Should I specify a computer name/ip with user/pwd?
David.Chu.ca
A: 

For a remote computer:

$wmi = Get-WmiObject -Class Win32_OperatingSystem -Computer RemoteComputerName
$wmi.ConvertToDateTime($wmi.LastBootUpTime)
aphoria
A: 

FYI, if you are on the PowerShell Community Extensions 2.0 Beta, you can use Get-Uptime e.g.:

PS> Get-Uptime

Uptime                                LastBootUpTime
------                                --------------
00:44:01.4401754                      3/21/2010 12:07:17 AM
Keith Hill