Friday, June 4, 2021

VM clone create powershell script

 

#$srcvms = get-vm -location "LAB" | select -expandproperty Name (for complete cluster or DC)

$srcvms = Get-Content c:\ry\ansible\vmname.txt

Foreach ($srcvm in $srcvms) {


#$srvcvms_strip = $srcvm -replace "LAB_"


new-vm -name "Clone_$srcvm" -vm $srcvm -vmhost esx01 -datastore "datastore11" -DiskStorageFormat Thin


}

#####################

To run cloning on all VMs at a time use below.

########################

#$srcvms = get-vm -location "LAB" | select -expandproperty Name (for complete cluster or DC)

$srcvms = Get-Content c:\ry\ansible\vmname.txt

Foreach ($srcvm in $srcvms) {


#$srvcvms_strip = $srcvm -replace "LAB_"


new-vm -name "Clone_$srcvm" -vm $srcvm -vmhost esx01 -datastore "datastore11" -DiskStorageFormat Thin -RunAsync


}



No comments: