PowerShell script exchange
Post Reply
Andreas Neufert
VP, Product Management
Posts: 6742
Liked: 1407 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Example: Replica VM disk target and type

Post by Andreas Neufert » 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)


veremin
Product Manager
Posts: 20282
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Example: Replica VM disk target and type

Post by veremin »

Hmm, the code looks pretty familiar. :D
Andreas Neufert
VP, Product Management
Posts: 6742
Liked: 1407 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Example: Replica VM disk target and type

Post by Andreas Neufert » 1 person likes this post

Yes, this code is based on v.Eremin's (Vladimir Eremin) example. Credit go to him.
Andreas Neufert
VP, Product Management
Posts: 6742
Liked: 1407 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Example: Replica VM disk target and type

Post by Andreas Neufert »

Tested with v9.5U1
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests