Example: Replica VM disk target and type

PowerShell script exchange

Example: Replica VM disk target and type

Veeam Logoby Andreas Neufert » Thu Oct 23, 2014 10:24 pm 1 person likes this post

Hi,
Just a small code example for changing a VM datastore target in a replica job. You can change disk type ( thin / thick ) as well.
This code is based on v.Eremin's (Vladimir Eremin) example. Credit go to him.

Code: Select all
asnp VeeamPSSnapin

$JobnName = "testrep3"
$VmwareName = "esxi55u1"
$VMName = "empty"
$NewDatastoreName = "ds1-small"
$TargetDiskCreationMode = "Thin"  #"Thick" or "Thin"


$VmwareObject = Get-VBRServer | where {$_.Name -eq $VmwareName}
$ds = Find-VBRViDatastore -Server ($VmwareObject) | where {$_.Name -eq $NewDatastoreName}


$JobObject = Get-VBRJob -name $JobnName
$Options = $JobObject.GetOptions()
$Objects = $JobObject.GetObjectsInJob()


$SelectedObject = $Objects | where { $_.Name -eq $VMName }
$SelectedObjectInfo = $SelectedObject.Info

#Set Config File Target Location
$SelectedObjectInfo.ExtendedOptions.TargetOptions.TargetDatastoreName = $ds.Name
$SelectedObjectInfo.ExtendedOptions.TargetOptions.TargetDatastoreRef = $ds.Reference

#Set First Disk Target Location
$SelectedObjectInfo.ExtendedOptions.TargetOptions.DiskDestination[0].TargetDatastoreName = $ds.Name
$SelectedObjectInfo.ExtendedOptions.TargetOptions.DiskDestination[0].TargetDatastoreRef = $ds.Reference
$SelectedObjectInfo.ExtendedOptions.TargetOptions.DiskDestination[0].DiskCreationMode = $TargetDiskCreationMode

#Write Config
[Veeam.Backup.Core.CObjectInJob]::Update($SelectedObjectInfo)


Andreas Neufert
Veeam Software
 
Posts: 2198
Liked: 357 times
Joined: Wed May 04, 2011 8:36 am
Location: Germany
Full Name: @AndyandtheVMs Veeam PM

Re: Example: Replica VM disk target and type

Veeam Logoby v.Eremin » Fri Oct 24, 2014 8:52 am

Hmm, the code looks pretty familiar. :D
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 966 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Example: Replica VM disk target and type

Veeam Logoby Andreas Neufert » Fri Oct 24, 2014 9:52 am 1 person likes this post

Yes, this code is based on v.Eremin's (Vladimir Eremin) example. Credit go to him.
Andreas Neufert
Veeam Software
 
Posts: 2198
Liked: 357 times
Joined: Wed May 04, 2011 8:36 am
Location: Germany
Full Name: @AndyandtheVMs Veeam PM

Re: Example: Replica VM disk target and type

Veeam Logoby Andreas Neufert » Mon Mar 13, 2017 8:38 pm

Tested with v9.5U1
Andreas Neufert
Veeam Software
 
Posts: 2198
Liked: 357 times
Joined: Wed May 04, 2011 8:36 am
Location: Germany
Full Name: @AndyandtheVMs Veeam PM


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 10 guests