PowerShell script exchange
Post Reply
snzhang2
Influencer
Posts: 22
Liked: 1 time
Joined: Oct 12, 2016 3:17 pm
Full Name: Nan Zhang
Contact:

How to delete network mapping from replication job

Post by snzhang2 »

I need to change the network mapping for replication jobs and what I find is that if the source and destination network are on standard switches the Set-VBRViReplicaJob cmdlet can't update an existing mapping. This is not a problem for distributed switches. But if there is no existing mapping it all goes as expected.

So what I thought is to remove the existing network mapping and then remap it. But I can't find a way to remove the network mapping using the existing cmdlets. I tried (set-VBRViReplicaJob -enablenetworking:$false -Job $job) and it actually deleted the source VM from the job.

Also if there is a way to get the existing network mapping that would be nice. This will help identify if the replication job network mapping is correct or not.

Thanks in advance.
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: How to delete network mapping from replication job

Post by veremin »

I'm wondering what particular error you got while trying to set new mapping rules with the use of SourceNetwork and TargetNetwork parameters.
snzhang2
Influencer
Posts: 22
Liked: 1 time
Joined: Oct 12, 2016 3:17 pm
Full Name: Nan Zhang
Contact:

Re: How to delete network mapping from replication job

Post by snzhang2 »

The command:

Code: Select all

Set-VBRViReplicaJob -Job $job  -SourceNetwork $srcVBRNetwork -TargetNetwork $trgVBRNetwork -EnableNetworkMapping
runs to completion without any error (return code via $? is True). But the TargetNetwork doesn't get updated as expected.

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

Re: How to delete network mapping from replication job

Post by veremin »

Can you also share the portion where source and target networks get assigned to variables?
tsightler
VP, Product Management
Posts: 6035
Liked: 2860 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: How to delete network mapping from replication job

Post by tsightler »

I've run into this before. Here's a small example of code I use which wipes the existing mapping and saves that to the job just prior to setting the new mapping.

Code: Select all

# Remove the current NetworkMappings node if it already exist (possible bug) 
if ($job.Options.Options.RootNode.NetworkMappings) {
    $job.Options.Options.RootNode.RemoveChild($job.Options.Options.RootNode.SelectSingleNode("//NetworkMappings"))
}
Set-VBRJobOptions -Job $job -Options $job.Options

# Set the new mapping
Set-VBRViReplicaJob -Job $job -EnableNetworkMapping -SourceNetwork $src_net_map -TargetNetwork $tgt_net_map
snzhang2
Influencer
Posts: 22
Liked: 1 time
Joined: Oct 12, 2016 3:17 pm
Full Name: Nan Zhang
Contact:

Re: How to delete network mapping from replication job

Post by snzhang2 »

Thanks! That's exactly what I am after.

Unfortunately this code has the side effect of removing any existing VM mapping as well. Not sure why this would be the case as the the line for removing the mapping refers to "//NetworkMappings".
tsightler
VP, Product Management
Posts: 6035
Liked: 2860 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: How to delete network mapping from replication job

Post by tsightler »

I think this might be a bug in Set-VBRJobOptions, but I believe you can save them and remap easily enough, although I can't seem to dig up my example code for that.
snzhang2
Influencer
Posts: 22
Liked: 1 time
Joined: Oct 12, 2016 3:17 pm
Full Name: Nan Zhang
Contact:

Re: How to delete network mapping from replication job

Post by snzhang2 »

I have a script to map VM replicas (taken from this forum and modified to my needs) so the work-around now would be to perform the network mapping first and then the VM replica mapping after.

Thanks again!
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests