Press "Enter" to skip to content

Automated bulk IP address reconfiguration with Zerto Virtual Replication

Joshua Stenhouse 12

When configuring IP address changes in Zerto Virtual Replication (ZVR) one common challenge is data entry. Yes, it’s certainly easy to configure the new IP addresses in the GUI, but when you are protecting hundreds of VMs with hundreds of vNICs then using the GUI can become a problem. Not only will it take you a long time to configure each vNIC one by one, but you are introducing the risk of human error.

editvnic

To solve this challenge I created 2 PowerShell scripts to fully automate re-IP addressing in bulk. The first script “ZVR Bulk Re-IP Export v1.ps1” exports a list of every protected VM vNIC to a CSV with a column for each configuration item possible. You will need to protect every VM first for its vNIC info to be exported, edit the variables at the top of script for your environment, then run it to get the below output:

 zvrvmnics

You can now easily edit the CSV with all the new IP information required. Simply edit the variables at the top of “ZVR Bulk Re-IP Import v1.ps1” and run the script to import the re-IP settings. If all goes well you’ve just saved yourself many hours of manual work! To download both scripts click on the below link:

ZVR Bulk Re-IP v2.zip

If you haven’t updated already make sure you are on at least ZVR 4.5 U2 for the script to work (as it uses the manage VPG API introduced in 4.5). It also presumes all the VMs have VMware tools installed and is for vSphere to vSphere replication. If you like this script, found it useful and it saved you a lot of time please share this post on across your networks. Happy scripting,

Joshua

  1. Your export script works great – but there is an issue when I try to re-import- I’m getting a 400 error during the import – sort of lost with any ideas on how to resolve

    • Hey! First of all, thank you for downloading the script and giving it a go. This could be so many things, but let’s try to figure it out. Please can you tell me which version of Zerto you are using, and secondly, what target are you replicating the VMs to (another vCenter, Hyper-V, Azure etc)?

      • Tom Hall Tom Hall

        I’m seeing the 400 error on import as well. The export went without issue. Currently on Zerto 5.0 Update 1 Patch 2 Build 050121007, replicating to vCenter, and powershell version is 5.0.10586. I’ve never used REST Apis before, but I added some echoing of the variables it is building within the script and some of the URLs it is creating have spaces in it and I think that might be where the 400 is coming from. For example trying to pass “https://server:port/v1/vpgSettings/whatever/vms/whatever.vm-56399/nics/Network adapter 1” the spaces in “Network adapter 1”

  2. Tom Hall Tom Hall

    BTW, it is at line 206 in “ZVR Bulk Re-IP Import v1.ps1”

    $EditVMNIC = Invoke-RestMethod -Method PUT -Uri $EditVMNICURL -Body $VMNICJSON -Headers $zertoSessionHeader -ContentType $TypeJSON -TimeoutSec 100

    • Thanks for clarifying Tom! Let me check this out and come back to you as it wasn’t an issue when I last tested it.

      • Hey Tom. I have good news in that I found the problem. I hit the exact same issue and it turned out to be 2 fields in the CSV that I wasn’t configuring (I had left them blank, just as they come from the export script). They are VMNICFailoverDHCP and VMNICFailoverTestDHCP. Please can you set both to FALSE in the CSV and try it again for me? Given it took me 30 minutes of head scratching to figure is out I will edit the scripts to include this in the export and check on import for the value. If it hasn’t been set I’ll use FALSE by default. Will change the link to v2 when done.

  3. Reblogged this on Virtually Sober and commented:

    If you tried to use this example before 04/25/17 there was a typo in the export script which left 2 key fields blank subsequently causing an error on import. I’ve now fixed the issue so now is as good a time as any to give this cool script a run in your Zerto environment for bulk IP configuration.

    • Tom Hall Tom Hall

      Thank you for the quick turn around, Joshua. It is now error free, but I did notice that the v2 export script still leaves those DHCP fields as blank if the “Change vNIC IP Config…” is left at No. We currently do not have a test network and so my issue was around that VMNICFailoverTestDHCP field, so, I just manually put false in the CSV field and was good to go.

      • Thanks for the feedback Tom. Strange that it was blank as I just ran it again in my lab and I get both fields returned as FALSE. It could be something in the VPG config that returns null. For anyone reading this just as Tom did make sure you set both DHCP fields in the CSV to TRUE or FALSE before running the import script and you’ll be good to go.

  4. Dustin Dustin

    Ha. I just read your other blog about the API changes in 5.0 U3. I will review this and see if I can get this script working. Thanks!

  5. Hey Joshua,
    Thanks for this life saving script! I did made my life really easy now that I have to do lots of changes on my VPGs.

    Listen, I took a liberty to re-factor your script a little bit I was hoping to check if you’re OK with me featuring it on my GitHub page and my blog. I’m keeping the credits to your original script and etc.

    You can see it here: https://github.com/Gmagella/PowerShell/blob/master/ZertoVPGConfigExport.ps1

    The Blog post will link to your blog post, and my github version, if you’re OK.

    If not, I can take it down, no hard feelings.

    • Joshua Stenhouse Joshua Stenhouse

      Hey Geraldo! Thanks for reaching out. Please feel free to use it as you see fit and thank you for keeping my name in the credits.

Leave a Reply

%d bloggers like this: