PowerShell script exchange
Post Reply
filipsmeets
Enthusiast
Posts: 37
Liked: 3 times
Joined: Jun 26, 2019 3:28 pm
Full Name: Filip Smeets
Contact:

How to - CDP Network Mapping?

Post by filipsmeets »

I'm trying to set multiple network mappings for a CDP Policy using the Set-VBRCDPPolicy command.

Code: Select all

Connect-VBRServer

Connect-VIServer vcenter -Credential

$CDPPolicy = Get-VBRCDPPolicy -Name "CDP"

$SourceServer = Get-VBRServer -Type ESXi -Name 'dc1-esx'
$SourceNetwork = Get-VBRViServerNetworkInfo -Server $SourceServer

$TargetServer = Get-VBRServer -Type ESXi -Name 'dc2-esx'
$TargetNetwork = Get-VBRViServerNetworkInfo -Server $TargetServer |Where-Object{$_.NetworkName -like 'DRP*'}

$AllmyObject = @()


foreach($t in $TargetNetwork){
    $Name = $t.NetworkName.ToString().Substring(4)
    
    $s = $SourceNetwork | Where-Object{$_.NetworkName -like "$Name"}

    if(($null -ne $s) -and ($s.NetworkName -notlike '*TRUNK*')){
        
        $myObject = [PSCustomObject]@{
            SourceNetwork = $s
            TargetNetwork = $t
        }
        $AllmyObject += $myObject        
    }
}

$VBRCDPPolicyArg = @{
    Policy = $CDPPolicy
    SourceNetwork = $AllmyObject.SourceNetwork
    TargetNetwork = $AllmyObject.TargetNetwork
}

Set-VBRCDPPolicy @VBRCDPPolicyArg

Set-VBRCDPPolicy : Unable to validate network mapping configuration: the same network Source network: DC1-DVS-Workloads is specified as source and target
At line:1 char:1
+ Set-VBRCDPPolicy @VBRCDPPolicyArg
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-VBRCDPPolicy], Exception
+ FullyQualifiedErrorId : System.Exception,Veeam.Backup.PowerShell.Cmdlets.SetVBRCDPPolicy
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: How to - CDP Network Mapping?

Post by oleg.feoktistov »

Hi Filip,

When mapping source and target networks with Add/Set-VBRCDPPolicy cmdlets, members of network arrays are correlated by index: sourceNetwork[0] => targetNetwork[0], sourceNetwork[1] => targetNetwork[1] etc. So, the message you see is reflected if the source network at a given index is the same as the target network at a given index.

Thanks,
Oleg
filipsmeets
Enthusiast
Posts: 37
Liked: 3 times
Joined: Jun 26, 2019 3:28 pm
Full Name: Filip Smeets
Contact:

Re: How to - CDP Network Mapping?

Post by filipsmeets »

Hi Oleg

Thx for reaching out.
They don't seem similar to me.

PS E:\Scripts> $AllmyObject.SourceNetwork[0]


Uuid : 50 35 e1 6e 65 a5 b6 e6-fe 0d 19 10 4b 97 bf 2b
SwitchName : DCR1-DVS-Workloads
NetworkName : DCR1_VLAN1613_PROD_DMZPRIVATE
Id : 50 35 e1 6e 65 a5 b6 e6-fe 0d 19 10 4b 97 bf 2b
Name : DCR1-DVS-Workloads
Path : DCR1_VLAN1613_PROD_DMZPRIVATE
Type : ViDVS
NetworkId : dvportgroup-680
ViReference : dvportgroup-680




PS E:\Scripts> $AllmyObject.TargetNetwork[0]


Uuid : 50 35 6b 49 de 35 61 ea-cc a8 12 01 14 33 a7 32
SwitchName : DCR2-DVS-Workloads
NetworkName : DRP_DCR1_VLAN1613_PROD_DMZPRIVATE
Id : 50 35 6b 49 de 35 61 ea-cc a8 12 01 14 33 a7 32
Name : DCR2-DVS-Workloads
Path : DRP_DCR1_VLAN1613_PROD_DMZPRIVATE
Type : ViDVS
NetworkId : dvportgroup-567
ViReference : dvportgroup-567
filipsmeets
Enthusiast
Posts: 37
Liked: 3 times
Joined: Jun 26, 2019 3:28 pm
Full Name: Filip Smeets
Contact:

Re: How to - CDP Network Mapping?

Post by filipsmeets »

We changed the script as follow but are getting another error.

Code: Select all

Connect-VBRServer

Connect-VIServer vcenter -Credentials

$CDPPolicy = Get-VBRCDPPolicy |Where-Object{$_.Name -like '*gold*'}

$SourceServer = Get-VBRServer -Type ESXi -Name 'dcr1-esx-p021'
$SourceNetwork = Get-VBRViServerNetworkInfo -Server $SourceServer

$TargetServer = Get-VBRServer -Type ESXi -Name 'dcr2-esx-p011'
$TargetNetwork = Get-VBRViServerNetworkInfo -Server $TargetServer |Where-Object{$_.NetworkName -like 'DRP*'}

$SrcNet = @()
$TrgNet = @()

foreach($t in $TargetNetwork){
    $Name = $t.NetworkName.ToString().Substring(4)
    
    $s = $SourceNetwork | Where-Object{$_.NetworkName -like "$Name"}

    if(($null -ne $s) -and ($s.NetworkName -notlike '*TRUNK*')){
        
        $SrcNet += $s
        $TrgNet += $t
                
    }
}

$VBRCDPPolicyArg = @{
    Policy = $CDPPolicy
    EnableNetworkMapping = $true
    SourceNetwork = $SrcNet
    TargetNetwork = $TrgNet
}

Set-VBRCDPPolicy @VBRCDPPolicyArg
We are now getting the following error. The command is not accepting $CDPPolicy.

Set-VBRCDPPolicy : Object reference not set to an instance of an object.
At line:1 char:39
+ ... P - Gold' | Set-VBRCDPPolicy -EnableNetworkMapping -SourceNetwork $Sr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-VBRCDPPolicy], NullReferenceException
+ FullyQualifiedErrorId : System.NullReferenceException,Veeam.Backup.PowerShell.Cmdlets.SetVBRCDPPolicy

We tested the same with a Replication Job and there it works.
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: How to - CDP Network Mapping?

Post by oleg.feoktistov »

Hi Filip,

Sorry my answer took so long. Couldn't get ahold of a lab with CDP enabled immediately.
Tested your case though and couldn't reproduce any of the errors you encountered. Powershell does throw an error when trying to map the network to itself, but in other scenarios I could get CDP policies modified and working using your script sample. I would advise to contact our support and submit logs for further investigation. Please, also share the case id here so that we could follow it up.

Thanks,
Oleg
gschaffer
Novice
Posts: 9
Liked: 1 time
Joined: Nov 26, 2021 2:39 pm
Full Name: Guilherme Schaffer
Contact:

Re: How to - CDP Network Mapping?

Post by gschaffer »

in v12 the issue is still ther. Case 05951801
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests