VMware Cloud Community
blackbox11
Contributor
Contributor
Jump to solution

Scripted SRM - network mapping help

Hey guys,

Trying to script network selection for our DR site. Currently using below commands to map primary network name with DR network name. can someone suggest if there's a better way using these commands please.

# Update Network card for all VM's in cluster

Get-VM | Get-NetworkAdapter | ? {$_.NetworkName -eq "dvportgroup-19273" -or $_.NetworkName -eq "dvportgroup-21140" } |  Set-NetworkAdapter -NetworkName "ABC"

Get-VM | Get-NetworkAdapter | ? {$_.NetworkName -eq "dvportgroup-19274" -or $_.NetworkName -eq "dvportgroup-10114" } |  Set-NetworkAdapter -NetworkName "ABC_31"

Get-VM | Get-NetworkAdapter | ? {$_.NetworkName -eq "dvportgroup-241" -or $_.NetworkName -eq "dvportgroup-110125" } |  Set-NetworkAdapter -NetworkName "ABC_18"

About 10 additional networks needs to be mapped.

To clarify, got 16 networks on primary site across 2 VDS and they need to be  mapped to 10 port groups in DR site on a single VDS

Help greatly appreciated.

Cheers,

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Ok, so the thread title is a bit misleading :smileygrin:

You can store those mappings in a table, and then handle them in a ForEach loop.

Something like this for example

Note that the data from the inline mapping I used in the example, can also come from a CSV file with Import-Csv.

$mapping = @"

"SourceSitePg1","SourceSitePg2","RecoverySitePg"

"dvportgroup-19273","dvportgroup-21140","ABC"

"dvportgroup-19274","dvportgroup-10114","ABC_31"

"dvportgroup-241","dvportgroup-110125","ABC_18"

"@

foreach($line in ($mapping | ConvertFrom-Csv)){

    Get-VM | Get-NetworkAdapter | where{$line.SourceSitePg1,$line.SourceSitePg2 -contains $_.NetworkName} | Set-NetworkAdapter -NetworkName $line.RecoverySitePg

}

Another option is to use a hash table.

That way you are able to eliminate the Where-clause altogether.

$mapping = @"

"SourceSitePg","RecoverySitePg"

"dvportgroup-19273","ABC"

"dvportgroup-21140","ABC"

"dvportgroup-19274","ABC_31"

"dvportgroup-10114","ABC_31"

"dvportgroup-241","ABC_18"

"dvportgroup-110125","ABC_18"

"@

$pgTab = @{}

foreach($line in ($mapping | ConvertFrom-Csv)){

    $pgTab.Add($line.SourceSitePg,$line.RecoverySitePg)

}

Get-VM | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $pgTab.Item($_.NetworkName)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

4 Replies
LucD
Leadership
Leadership
Jump to solution

Not sure why you are doing this, isn't that something that you define in the Network Mapping under the Inventory Mapping?

If you have those mappings in a table or CSV file, you could do this in a ForEach loop.

Just run through the table.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
blackbox11
Contributor
Contributor
Jump to solution

Hi LucD,

Thanks for quick reply, client don't have SRM, trying to implement it using  3par replication at the remote site.

We didn't want to go CSV route as we will need to get the output on primary site which might not be possible during a DR scenario

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, so the thread title is a bit misleading :smileygrin:

You can store those mappings in a table, and then handle them in a ForEach loop.

Something like this for example

Note that the data from the inline mapping I used in the example, can also come from a CSV file with Import-Csv.

$mapping = @"

"SourceSitePg1","SourceSitePg2","RecoverySitePg"

"dvportgroup-19273","dvportgroup-21140","ABC"

"dvportgroup-19274","dvportgroup-10114","ABC_31"

"dvportgroup-241","dvportgroup-110125","ABC_18"

"@

foreach($line in ($mapping | ConvertFrom-Csv)){

    Get-VM | Get-NetworkAdapter | where{$line.SourceSitePg1,$line.SourceSitePg2 -contains $_.NetworkName} | Set-NetworkAdapter -NetworkName $line.RecoverySitePg

}

Another option is to use a hash table.

That way you are able to eliminate the Where-clause altogether.

$mapping = @"

"SourceSitePg","RecoverySitePg"

"dvportgroup-19273","ABC"

"dvportgroup-21140","ABC"

"dvportgroup-19274","ABC_31"

"dvportgroup-10114","ABC_31"

"dvportgroup-241","ABC_18"

"dvportgroup-110125","ABC_18"

"@

$pgTab = @{}

foreach($line in ($mapping | ConvertFrom-Csv)){

    $pgTab.Add($line.SourceSitePg,$line.RecoverySitePg)

}

Get-VM | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $pgTab.Item($_.NetworkName)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

blackbox11
Contributor
Contributor
Jump to solution

LucD, you are a star!

Will give this a try and update you guys. I will share my script once tested, hopefully will help someone in similar position.

Reply
0 Kudos