27 Replies Latest reply: Mar 18, 2014 11:00 AM by Mike Elam RSS

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


      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:\\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):





      $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



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

      $msg=Invoke-Expression -command $command


      If you have useful powercli or tricks, please share