Vmware Power Cli
Quickly Add Mulltiple VM nics
we can automate the addition of vmnics to any of our virtual machines. The commandlet we use is the new-networkadapter commandlet. We can specify several parameters with this commandlet including the VM we want to add to, the networkname or port group to attach the network adapter to, the type (vmxnet3, etc) and we can specify we want the network adapter to startconnected.
#new-networkadapter -vm <vmname> -NetworkName "<Port group name>" -Type "VMXNET3" -startconnected
If we want to add a specific number of network adapters to a certain VM, we can do that with a for each loop with a count statement. The below will add (4) new network adapters to a specific VM identified with the -vm parameter.
Multiple -4 vmnics, list of VMs : We can nest our foreach loop inside another foreach loop and usea variable to read in the contents of a VM list.
********************************************************************************
#Multiple vmnics on multiple VMs $vms=get-content c:vms.txt foreach ($vm in $vms){ foreach ($i in 1..4){ new-networkadapter -vm $vm -NetworkName "Port group name" -Type "VMXNET3" -startconnected } }
**********************************************************************************************************
Get-VIEvent cmdlet - ESXI Host login failures and can be queried as such.
#Get-VIEvent -MaxSamples 100000 -Start (Get-Date).AddDays(-1) -Type Warning | Where {$_.FullFormattedMessage -match “restarted”} |select CreatedTime,FullFormattedMessage | sort CreatedTime –Descending
********************************************************************************
List VMs Running
On Hosts
Connect the ESXi host via SSH and issue this command to list all VMs:
vim-cmd vmsvc/getallvms
Get VM State
To get the current state of the VM, issue the command:
vim-cmd vmsvc/power.getstate VMID
Shutdown the VM using this command:
vim-cmd vmsvc/power.shutdown VMID
If the VM fails to shutdown, you can run:
vim-cmd vmsvc/power.off VMID
**********************************************************************************
Comments
Post a Comment