Waclaw Chrabaszcz
... there is no spoon ...

PowerShell – The first kiss with VMware PowerCLI

Saturday, October 5, 2013 8:16 AM

Long time ago VMware published they own PowerShell module. Let's take a look on it.

First we need to download and install the module.
https://my.vmware.com/web/vmware/details?productId=285&downloadGroup=VSP510-PCLI-510
It is a really simple Next, Next installation, and it creates a shortcut on your desktop.

Here you have few simple examples.

#add ESXi host
$myServer="localhost"
$MyVMHost = "192.168.1.10"
$myLocation = "Cluster1"
$MyUsername = "root"
$MyPassword = "Password1"
Add-VMHost -Server $myServer -Name $MyVMHost -Location $myLocation -User $MyUsername -Password $MyPassword -force

#rename datastore
Get-Datastore -Name Datastore1 | Set-Datastore -Name datastoreESX1
Get-Datastore -Name "datastore1 (1)" | Set-Datastore -Name datastoreESX2

#storage migration
$myDisk = Get-VM -Name "New Virtual Machine" | Get-HardDisk
$myDatastore1 = Get-Datastore -Name "datastoreESX2"
Move-hardDisk -HardDisk $myDisk -Datastore $myDatastore1 -StorageFormat "Thin"

#put host into Mintenence mode
$cluster = Get-Cluster -VMHost "192.168.1.10"
$task = Set-VMHost -VMHost "192.168.1.10" -State "Maintenance" –RunAsync
Get-DrsRecommendation -Cluster $cluster | where {$_.Reason -eq "Host is entering maintenance mode"} | Apply-DrsRecommendation
$vmhost = Wait-Task $task

#back host online
Set-VMHost -VMHost "192.168.1.10" -State "Connected"

Looking forward for opportunity to write real production script.




Feedback

# re: PowerShell – The first kiss with VMware PowerCLI

It's really a great jvzoo academy review. I would strongly recommend it to anyone who would like to get started with idea generation. It would be greater if Sam has provided a pdf format, compiled course material for the entire course..
5/10/2017 6:55 AM | anonymous

# re: PowerShell – The first kiss with VMware PowerCLI

Very useful. I will bookmark this artical and read later. Thank you so much :)
You can see more at syndlab review 6/12/2017 5:37 PM | Jerry Moss

Post a comment