It was hard to find a script like this to get the boottime in Windows.. So I ended up writing one.. it uses the command "wevtutil"..
It can be tested manually by running the following command locally
wevtutil qe Microsoft-Windows-Diagnostics-Performance/Operational /rd:true /q:"*[System[(EventID=100)]]" /e:Events /c:1 /f:text | FINDSTR "Date Duration""
or from a remote system using the following command
wevtutil qe Microsoft-Windows-Diagnostics-Performance/Operational /rd:true /q:"*[System[(EventID=100)]]" /e:Events /c:1 /f:text /r:$vmname /u:username /p:password | FINDSTR "Date Duration""
For $vmname.. you can either give the ipaddress or the FQDN name of the remote system. You normally need admin access to get the access to the event.
Perl Script to get for about 50 virtual machines.. to measure bootimes.. and sort it based on the boot time.. To install File::Slurp you can use the following command in linux
"yum install perl-File-Slurp"
Below is the script
use File::Slurp;
use strict;
open (OUTPUT, "+>>bootTimes.txt") or die "Can not open bootTime.txt: $!";
my $VM = 1;
for ($VM;$VM<=50;$VM++){
my $vmname = "vmlc1-$VM.vdi.test.com";
my $cmd = "wevtutil qe Microsoft-Windows-Diagnostics-Performance\/Operational \/rd:true \/q:\"\*\[System\[\(EventID\=100\)\]\]\" \/e\:Events \/c\:1 \/f\:text \/r\:$vmname \/u:Administrator \/p:password \| FINDSTR \"Date Duration\"";
my $bootmsg = qx($cmd);
if ( $bootmsg =~ m/\s+Date:\s+(.+)\s+\S+\s+\S+\s+:\s+(.+)ms/){
my $bootDate = $1;
my $bootTime = $2;
my $message = "vmlc1-$VM.vdi.test.com, $bootDate, $bootTime\n";
print OUTPUT $message;
}
}
my $str = read_file("bootTimes.txt");
print $str;
$str = join "",
map { $_->[0]."\n" }
sort { $a->[1] <=> $b->[1] }
map { [$_, (split)[-1]] }
split /\n/, $str;
print $str;