Powercli: Difference between revisions

From roonics
Jump to navigation Jump to search
Line 25: Line 25:
<pre>$esxis = Get-VMHost
<pre>$esxis = Get-VMHost
Get-ViEvent -entity $esxis -Start (Get-Date "10:00 10/09/2016") -Finish (Get-Date "15:00 10/09/2016") -MaxSamples ([int]::MaxValue) | Where {$_.FullFormattedMessage -eq "Host has booted."}
Get-ViEvent -entity $esxis -Start (Get-Date "10:00 10/09/2016") -Finish (Get-Date "15:00 10/09/2016") -MaxSamples ([int]::MaxValue) | Where {$_.FullFormattedMessage -eq "Host has booted."}
</pre>
Example output:
<pre style="color: silver; background: black; width: 800px">
EventTypeId          : esx.audit.host.boot
Severity            :
Message              :
Arguments            :
ObjectId            : host-155553
ObjectType          : HostSystem
ObjectName          : vsphere-host-01
Fault                :
Key                  : 117978286
ChainId              : 117978286
CreatedTime          : 10/09/2016 13:11:21
UserName            :
Datacenter          : VMware.Vim.DatacenterEventArgument
ComputeResource      : VMware.Vim.ComputeResourceEventArgument
Host                : VMware.Vim.HostEventArgument
Vm                  :
Ds                  :
Net                  :
Dvs                  :
FullFormattedMessage : Host has booted.
ChangeTag            :
DynamicType          :
DynamicProperty      :
</pre>
</pre>

Revision as of 10:36, 15 March 2019

Powercli

Useful Commands

Update vmTools with no reboot

Get-VM "<vm_name>" | Update-Tools -NoReboot

Create snapshot

new-snapshot -vm <vm_name> -name snapshot_test

Remove snapshot

get-snapshot -vm <vm_name> | remove-snapshot

vMotion

get-vm -Name <vm_name> | move-vm -Destination <hostname_or_host_ip>

Storage vMotion

Get-VM "<vm_name>" | Move-VM -Datastore <datastore_name>

List all virtual machines with snapshots

get-vm | get-snapshot | format-list vm,name

List vmx file locations for vm's

Get-View -ViewType VirtualMachine | % { $_.Config.Files.VmPathName }

Get host boot up time/date

$esxis = Get-VMHost
Get-ViEvent -entity $esxis -Start (Get-Date "10:00 10/09/2016") -Finish (Get-Date "15:00 10/09/2016") -MaxSamples ([int]::MaxValue) | Where {$_.FullFormattedMessage -eq "Host has booted."}

Example output:

EventTypeId          : esx.audit.host.boot
Severity             :
Message              :
Arguments            :
ObjectId             : host-155553
ObjectType           : HostSystem
ObjectName           : vsphere-host-01
Fault                :
Key                  : 117978286
ChainId              : 117978286
CreatedTime          : 10/09/2016 13:11:21
UserName             :
Datacenter           : VMware.Vim.DatacenterEventArgument
ComputeResource      : VMware.Vim.ComputeResourceEventArgument
Host                 : VMware.Vim.HostEventArgument
Vm                   :
Ds                   :
Net                  :
Dvs                  :
FullFormattedMessage : Host has booted.
ChangeTag            :
DynamicType          :
DynamicProperty      :