For the VMware Xenapp/XenDesktop administrator
out there that wants to quickly use powershell
to check VM management via your vCenter
installation, here is a quick reference. The
following commands are either run from within
the powershell context (remove "powershell" from
any of the commands noted below) or directly
from command-line.
General Commands:
- To quickly test if your VMware is
working (open by clicking on the vmware
powershell icon) or open a cmd prompt and
typing "powershell" + enter. Type in >
get-vc
- Key in the vCenter Neme and log in your
admin and password followed by the following
to display a list of VM's currently being
managed by vCenter. Type in >
get-vm
- To connect an ESX host or cCenter
server. Type in:
connect-viserver
- To get a complete list of available
Cmdlets. Type in:
get-vicommand
- One other option to se a list of
available cmdlets. Type in
get-vitoolkitdocumtation to view the
vmware help file.
- To open the vmware community for VSphere
PowerCLI website. Type in
get-vitoolkitcommunity
- Example login:
get-vc
yourwebsite.net -user
yourid
-password
yourpassword
- To trigger
a rescan across all ESX hosts which happen
to be managed by vCenter add the following
three commands in the following. Type in
get-vmhost | get-vmhoststorage -rescanallhba
-
To force an esx
host into maintenance mode >
get-vmhost -name
yourhostname
| set-vmhost -state maintenance
-
view any and
all vm's and display back which ones are set
to local storage >
get-datastore
|where {$_.name -match
"datastore|local|storage"} |get-vm
| get-harddisk | select filename |
export-csv c:\%computername%\localhosts.csv
-
cluster
creation command:
new-cluster
-location (get-datacenter -name
'your new
name' get- folder -Name
'new
foldername') -name 'new
foldername'-HAEnabled
-HAAdmissionControlEnabled -HAFailoverLevel
2 -DRSEnabled -DRSMode PartiallyAutomated
-
add an esx host
to a cluster >
add-vmhost
your.host.name -location (get-datacenter
'yourname') -user root -password
yourpassword
-
trigger vmotion
and move a vm from one esh host to another >
move-vm
–vm (get-vm -name 'yourvmname') -destination
(get-vmhost your.site.name)
-
take a snapshot
of many vm's using a wildcard * >
get-vm
yourhoststring* | 'foreach { '$_ |
new-snapshot -name ($_.Name + "-Current")'}
-
Managing
CDRom Drives or Floppy Drives with Powershell:
- in the event you want to only disconnect
any currently connected floppy drives, key
in the following powershell command >
get-vm |
get-floppydrive | set-floppydrive
-connected:$false
- in the event you want to only disconnect
any currently connected cdrom drives, key in
the following powershell command >
get-vm |
get-cddrive | set-cddrive -connected:$false
- int he event you want to from command
line clear any iso mappings, use the
following powershell command >
get-vm |
get-cddrive | set-cddrive -nomedia
Network Adapter Settings:
- to acquire a list of all port mappings >
get-vm | get-networkadapter
- to list any and all vm's and their ip
address key in the following command >
get-vm | select
name, @{name="ip"; expression={foreach($nic
in (get-view
$_.id).guest.net) {$nic.ipaddress}}}