Using Veeam Powershell to Manage ReIP Rules
Hello! Welcome to my First Veeam PowerShell Script! I have been working on tons of migrations using Veeam Backup and Replication and need to create re-ip rules to update the static IP assignments. Obviously the first rule of scripting if you do something more than once, automate! I was bad at this one, I originally tried and gave up so I did about 20 manually which started to become a huge headache.
Thanks to Marcus Puckett (@mpuckett259) he helped me on the side figure out the syntax to get the rule to append and not overwrite. See below for the script. Check out the Github for the bits!
Pre-Requsites
Link to Script
Preparing to Execute the Script
The script is pretty straight forward, just update the CSV file and then you execute the script.
1#Define Variables
2param
3(
4 [Parameter(Mandatory=$False,
5 HelpMessage='Path to CSV to Import')]
6 [string[]]$csvlist
7)
8
9#Load Veeam Plugin
10Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
11
12#Check if CSV was specified, if not prompt.
13If($csvlist -eq $NULL){
14 $csvlist = Read-host -Prompt "Csv to import"
15}
16If((Test-Path $csvlist) -eq $False){Write-host "Could not find CSV.";break}
17
18#Import CSV
19$iplist = Import-csv "$csvlist"
20
21#Cycle through each row and add in the ReIP Rule
22Foreach ($item in $iplist) {
23 $Description = $item.Description
24 $Job = $item.Job
25 $SourceIp = $item.SourceIp
26 $SourceMask = $item.SourceMask
27 $TargetIp = $item.TargetIp
28 $TargetMask = $item.TargetMask
29 $TargetGateway = $item.TargetGateway
30 $DNS1 = $item.DNS1
31 $DNS2 = $item.DNS2
32
33 $currentiprules = Get-VBRJob -Name $Job | Get-VBRViReplicaReIpRule
34 $newiprule = New-VBRViReplicaReIpRule -SourceIp $SourceIp -SourceMask $SourceMask -TargetIp $TargetIp -TargetMask $TargetMask -TargetGateway $TargetGateway -DNS $DNS1,$DNS2 -Description $Description
35 $newrules = @($currentiprules) + @($newiprule)
36 $replicajob = Get-VBRJob -Name $Job
37 Set-VBRViReplicaJob -Job $replicajob -EnableReIp -ReIpRule $newrules
38
39}
Execute the Script
- Run .\Create-VeeamReIPRule.ps1 pathto.csv