wen

Using PowerShell to provision Nimble Zero Copy Clone to ESXi server

Discussion created by wen Employee on Jan 15, 2014
Latest reply on Feb 3, 2014 by Justin Rich

Here's a quick & dirty script to perform the following task:

  • create zero copy clone of VMFS volume
  • provision clone to ESXi host follow by rescan
  • write new signature + rename VMFS volume
  • register every VM in the new clone in ESXi host

 

 

NOTE:

-plink should be downloaded & installed in the appropriate directory; my example is using plink executable in c:\secloud folder

-script could use some TLC in terms of error checks and prompt for user input; when time permits, I will enhance it; of course, you are welcome to modify/add to source and contribute back, isn't that the whole point of a kick-*** community like nimble connect?

 

Usage

In PowerCLI, simply execute the script with the source code below

 

In PowerShell, run the following commands prior to execution of the script:

add-PSSnapin VMware.VimAutomation.Core

Set-ExecutionPolicy unrestricted -confirm:$false -force

 

Source code:

#get array to clone the base vol

$user="admin"

$pw="arraypass"

$array="mynmblearray.lab"

$plink="c:\secloud\plink.exe"

$name='What name do you want for the clone?'

 

 

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

$remotecmd1="vol --clone sourcevolname --snapname nameofsnapshottoclone --clonename"

$command=$plink+" "+$plinkarrayoptions+" "+$remotecmd1+" "+$name+" --initiatorgrp esx55hulk"

 

 

$msg=Invoke-Expression -command $command

$msg

 

 

#VMW side task

connect-VIServer -Server 192.168.10.1 -User root -Password pass

$esxhost = '192.168.10.2'

 

#get new clone provisioned to ESX host

$esxcli = Get-EsxCli -VMhost $esxhost -ErrorAction Stop

Get-VMHost | Get-VMHostStorage -RescanAllHba

 

 

$snap=$esxcli.storage.vmfs.snapshot.list($null, $null)

$snapobject= $snap | select-object -property VMFSUUID

$uuid=$snapobject.VMFSUUID

$esxcli.storage.vmfs.snapshot.resignature($null, $uuid)

sleep 100

get-datastore | where {$_.Name -match "snap"} | Set-Datastore -Name $name

 

 

new-folder $name -Location parentfoldername

 

 

#register all VMs in the datastore

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

Outcomes