Handy VMware vSphere PowerCLI Cmdlets


Connect to vShere Server (vCenter/ESX/ESXi Host)

Connect-VIServer -Server $vhost -Protocol $protocol -User $user -Password $password

Disconnect vSphere Server

Disconnect-VIServer -Confirm:$False

Poweron Virtual Machine

Get-VM -Name $VMName | Start-VM

Shutdown Virtual Machine

Get-VM -Name $VM_Name | Shutdown-VMGuest

Reset Virtual Machine

Get-VM -Name $VM_Name | Restart-VM

Disconnect Network Adapter on Virtual Machine

Get-VM -Name $VM_Name | Get-NetworkAdapter | Set-NetworkAdapter -Connected:$false

Connect Network Adapter on Virtual Machine

Get-VM -Name $VM_Name | Get-NetworkAdapter | Set-NetworkAdapter -Connected:$true

Check Network Adapters Connection State on VMs

Get-VM | Get-NetworkAdapter | Select-Object Parent,ConnectionState

Move Virtual Machine to different Port group

Get-VM -Name $VM_Name | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $new_port_group

Register Virtual Machines by traversing Datastore directories

cd $vm_datastore_path
$vmdirectorylist=Get-ChildItem -Name W7-*

foreach($vmdirectory in $vmdirectorylist)
{
    cd $vm_datastore_path\$vmdirectory
    $vmxFile=Get-Item *.vmx
    New-VM -name $vmdirectory -VMHost $vHost -VMFilePath $vmxFile.DatastoreFullPath
}

Add NFS NAS as a new Datastore

New-Datastore -Nfs -VMHost $ESXiHost -Name $nfs_datastore_name -Path $nfs_mount_point -NfsHost $nfs_ip_address

Copy Directory from One Datastore to Other/Same Datastore Recursively

Copy-DatastoreItem $source_datastore\$source_directory $destination_datastore -Recurse

Enable SSH on ESXi Host

Get-VMHost "192.168.24.201" | Get-VMHostService | Where {$_.Key -eq "TSM-SSH"} | Start-VMHostService

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s