Skip to content

Latest commit

 

History

History
 
 

cloneVM

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Clone a VM using PowerShell

Warning: this code is provided on a best effort basis and is not in any way officially supported or sanctioned by Cohesity. The code is intentionally kept simple to retain value as example code. The code in this repository is provided as-is and the author accepts no liability for damages resulting from its use.

This powershell script clones a VM.

Download the script

Run these commands from PowerShell to download the script(s) into your current directory

# Download Commands
$scriptName = 'cloneVM'
$repoURL = 'https://raw.githubusercontent.com/bseltz-cohesity/scripts/master/powershell'
(Invoke-WebRequest -Uri "$repoUrl/$scriptName/$scriptName.ps1").content | Out-File "$scriptName.ps1"; (Get-Content "$scriptName.ps1") | Set-Content "$scriptName.ps1"
(Invoke-WebRequest -Uri "$repoUrl/cohesity-api/cohesity-api.ps1").content | Out-File cohesity-api.ps1; (Get-Content cohesity-api.ps1) | Set-Content cohesity-api.ps1
# End Download Commands

Components

  • cloneVM.ps1: the main powershell script
  • cohesity-api.ps1: the Cohesity REST API helper module

Place the files in a folder together and run the main script like so:

./cloneVM.ps1 -vip mycluster `
              -username myusername `
              -domain mydomain.net `
              -vmName myvm `
              -vCenterName myvcenter.mydomain.net `
              -datacenterName mydatacenter `
              -hostName esx1 `
              -folderName myFolder `
              -networkName 'VM Network' `
              -poweron `
              -prefix clone-

Parameters

  • -vip: Cohesity cluster to connect to
  • -username: Cohesity username (e.g. admin)
  • -domain: (optional) Active Directory domain (defaults to 'local')
  • -vmName: Name of VM to recover
  • -prefix: (optional) add a prefix to the VM name during restore
  • -vCenterName: (optional)vCenter protection source to recover to
  • -datacenterName: (optional) name of vSphere data center to recover to
  • -hostName: (optional) name of vSphere host to recover to
  • -folderName: (optional) name of vSphere folder to recover to
  • -networkName: (optional) VM Network to attach the VM to
  • -poweron: (optional) power on the VMs during restore (default is false)
  • -detachNetwork: (optional) leave VM network disconnected (default is false)