wen

Nugget:Useful vSphere PowerCLI commands + ways to execute Nimble CLI within PowerCLI

Discussion created by wen Employee on Dec 3, 2013
Latest reply on Mar 18, 2014 by Mike Elam

I have been playing around with PowerCLI lately and come across a few useful commands for automating daunting tasks in vSphere:

 

If you happen to clone a datastore and want to automatically register all VMs in there, here's a one liner to do it (replace host + datastore path + datastore name for your own environment):

dir "vmstores:\10.18.127.170@443\SJNimbleTM\$name\*\*.vmx" | % {New-VM -VMHost $esxhost -VMFilePath $_.DatastoreFullPath -Location $name}

 

After you register the VMs, you certainly want to power them on (replace the name match with specific VMs of interest, assuming power on order matters for you, otherwise, simply leave out the condition statement

get-folder $name | get-vm | where {$_.Name -match "1"} | start-vm

Get-VMQuestion | Set-VMQuestion -DefaultOption -Confirm:$false

 

If you want to have just one script to execute both vSphere and Nimble tasks, you can leverage plink to execute remote commands on Nimble array (thanks Nicholas S. for pointing this out):

$user="root"

$pw="lol"

$array="mynimble.nimble.com"

$plink="c:\users\gorilla\plink.exe"

$name=Read-Host 'name of volume to delete'

 

$plinkarrayoptions="$array -l $user -pw $pw"

$remotecmd1="vol --offline"

$remotecmd2="vol --delete"

$command=$plink+" "+$plinkarrayoptions+" "+$remotecmd1+" "+$name+" --force"

 

$msg=Invoke-Expression -command $command

$msg

 

$command2=$plink+" "+$plinkarrayoptions+" "+$remotecmd2+" "+$name+"

$msg=Invoke-Expression -command $command

$msg


If you have useful powercli or tricks, please share

Outcomes