Hi,
i went tho many notes. like
Get-VM -location xxx | `
where {$_.PowerState -eq "PoweredOn"} | `
Get-Stat -Stat sys.uptime.latest -MaxSamples 1 -Realtime | `
select Entity,
@{Name="Boottime";
Expression={(Get-Date).AddSeconds(- $_.value).ToString("yy/MM/dd HH:mm:ss")}} |export-csv c:\temp\sf-pete-vm-uptime.csv
$report = @() | |
Get-VM -location xxx | Get-View | %{ | |
$row = "" | select Name, PowerState, LastBoot, LastSuspend, TotalSuspend | |
$row.Name = $_.Name | |
$row.PowerState = $_.runtime.powerState | |
$row.LastBoot = $_.runtime.bootTime | |
$row.LastSuspend = $_.runtime.suspendTime | |
$row.TotalSuspend = $_.runtime.suspendInterval | |
$report += $row | |
} | |
$report |
But they do not work ...
Anyone has a final & working , script for getting the uptime of vm ?
thanks
You can also use something like below, Requirement is VMware tools should be present on requested VMs, You will require same username password for windows and have permissions also on Linux root or anyother username password should be same., It will directly pull Uptime/boottime from inside vm.
$report = @()
Get-VM | Where-Object {$_.powerstate -eq "PoweredOn"} | ForEach-Object {
$os = $_.extensiondata.Guest.GuestFullName
if ($os -match "Windows") {
$test = Invoke-VMScript -VM $_ -ScriptText "(Systeminfo)[11]" -GuestUser Domain\username -GuestPassword password
$test = $test.ScriptOutput -replace ("System Boot Time: ", "")
}
else {
$test = Invoke-VMScript -VM $_ -ScriptText "uptime" -GuestUser Root -GuestPassword Password
}
$row = "" | select Name, Boottime
$row.Name = $_.Name
$row.Boottime = $test
$report += $row
}
$report
You can also use something like below, Requirement is VMware tools should be present on requested VMs, You will require same username password for windows and have permissions also on Linux root or anyother username password should be same., It will directly pull Uptime/boottime from inside vm.
$report = @()
Get-VM | Where-Object {$_.powerstate -eq "PoweredOn"} | ForEach-Object {
$os = $_.extensiondata.Guest.GuestFullName
if ($os -match "Windows") {
$test = Invoke-VMScript -VM $_ -ScriptText "(Systeminfo)[11]" -GuestUser Domain\username -GuestPassword password
$test = $test.ScriptOutput -replace ("System Boot Time: ", "")
}
else {
$test = Invoke-VMScript -VM $_ -ScriptText "uptime" -GuestUser Root -GuestPassword Password
}
$row = "" | select Name, Boottime
$row.Name = $_.Name
$row.Boottime = $test
$report += $row
}
$report
Thanks, This looks is the ONLY way .. ie directly talking to the windows OS with Invoke-VMScript
Surprisingly even with vmware tools installed no way to get accurate info with promising commands (only on paper ) Get-Stat -Stat sys.uptime.latest..
Thanks, How do it get this in export-csv Please ?
on the last line replace $report with below line.
$report | Export-Csv -NoTypeInformation -Path c:\temp\info.csv
Apart from your can pull information on Windows servers using wmi as well,
ie:
Get-WmiObject -class win32_operatingsystem -ComputerName Localhost | Select-Object CSName, @{N="uptime"; E={$_.converttodatetime($_.LastBootUpTime)}}
I tried $report | Export-Csv -NoTypeInformation -Path c:\temp\info.csv already
But the o/p in the csv file shows name but the boottime coloum is empety .. not sure what is wrong .. can u Please re-check kunaludapi
thanks
Invoke-VMScript works only on PowerCLI 32-bit right?
Only when running against a VM on vSphere server earlier than 5.0
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I am not sure what could be wrong here, i am tring to install vmware tool in bulk .. tried below to test, nothing happens
get-vm vm1 |Invoke-VMScript -guestcredential $c3 -ScriptType bat msiexec.exe /i "D:\setup64.exe" /s /v /qn ADDLOCAL=All
get-vm vm1 |Invoke-VMScript -hostcredential $c3 -guestcredential $c3 -ScriptType bat msiexec.exe /i "D:\VMware Tools.msi" ADDLOCAL=ALL /qn
===
But below works
get-vm vm1 |Invoke-VMScript -guestcredential $c3 -ScriptType bat dir
If you want to upgrade vmware tools use update manager for that, as to run script inside VM, vmware tools should be present.
You didn't state if there were any error messages, but try specifying the command to execute as a string.
Like this
get-vm vm1 | Invoke-VMScript -guestcredential $c3 -ScriptType bat -ScriptText "msiexec.exe /i D:\setup64.exe /s /v /qn ADDLOCAL=All"
But note that you need to already have the VMware Tools installed to use the Invoke-VMScript cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I am exploring Sysinternal psexec tool for this.
I have posted a Q on their portal tho
======================================================================================================================================================
Hi,
I am trying to insall vmware tools on a windows vm with below cmd ..it hangs below
psexec \\10.xxx -u domain\id
-p passwd msiexec.exe /i "D:\setup[64].exe" /s /v /qn ADDLOCAL=All -
qn
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
Can someone Please help ?
======================================================================================================================================================
Have a look at KB1018377 to see the silent install options for the VMware Tools sw.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference