From 238c173ee6ed78ba59070ca58535db8ffb4d05a4 Mon Sep 17 00:00:00 2001 From: Jitendra Singh Date: Wed, 8 Jul 2020 23:01:45 +0530 Subject: [PATCH 1/4] adds function Copy-NsxIpset --- module/PowerNSX.psm1 | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/module/PowerNSX.psm1 b/module/PowerNSX.psm1 index cd5468eb..371f19b4 100644 --- a/module/PowerNSX.psm1 +++ b/module/PowerNSX.psm1 @@ -36416,6 +36416,63 @@ function Copy-NsxEdge{ } end {} } +function Copy-NsxIpSet { + <# + .SYNOPSIS + Copies NSX IP sets from Primary NSX manager to Secondary NSX Manager + + .DESCRIPTION + This Function Helps you to copy NSX Ip sets from One NSX Manager to Another + + .EXAMPLE + Copy-NsxIpSet -PrimaryNsxManager Nsx01.xyz.com -SecondaryNsxmanager Nsx02.xyz.com + + + + #> + [cmdletBinding()] + param ( + [parameter(Mandatory = $true)] + [string] $PrimaryNsxManager, + [parameter(Mandatory = $true)] + [string] $SecondaryNsxManager, + [parameter (Mandatory = $true)] + [pscredential] $credential + ) + begin + { + Connect-NsxServer $PrimaryNsxManager -DisableVIAutoConnect -Credential $credential + $NsxIpSets = @(Get-NsxIpSet) + Disconnect-NsxServer + } + process + { + Connect-NsxServer $SecondaryNsxManager -DisableVIAutoConnect -Credential $credential + Write-Verbose -Message "Syncing NsxIpSets from $PrimaryNsxManager to $SecondaryNsxManager" + foreach($Nsxipset in $NsxIpSets) + { + $IpSetExists = Get-NsxIpSet -Name $Nsxipset.Name -ErrorAction SilentlyContinue + if ($IpSetExists) + { + Write-Verbose -Message "Found the IPSet with Name $($NsxIpSet.Name)....Adding the Ip address" + try{ + Add-NsxIpSetMember -IPSet $IpSetExists -IPAddress $Nsxipset.value -ErrorAction stop -whatif + Write-Verbose -Message "updated the Ip set with name $($NsxIpset.name) and IpAddress $($NsxIpSet.value)" + } + catch{ + Write-Verbose -Message "Failed ! updating the Ip sets" + } + } + else{ + Write-Verbose -Message "Not Found ip set, Creating NsxIpSet $($NsxIpSet.Name)" + New-NsxIpSet -Name $NsxIpSet.Name -IPAddress $NsxIpSet.value + } + } + } +end { + Write-Verbose -Message "Sync Finished" +} +} #Call Init function _init From c1518bf97a2632e037b8459e7c8e1d0e0e84dabe Mon Sep 17 00:00:00 2001 From: Jitendra Singh Date: Mon, 13 Jul 2020 08:57:03 +0530 Subject: [PATCH 2/4] moved function from powernsx.psm1 --- module/PowerNSX.psm1 | 58 -------------------------------------------- 1 file changed, 58 deletions(-) diff --git a/module/PowerNSX.psm1 b/module/PowerNSX.psm1 index 371f19b4..fe3365c6 100644 --- a/module/PowerNSX.psm1 +++ b/module/PowerNSX.psm1 @@ -36416,63 +36416,5 @@ function Copy-NsxEdge{ } end {} } -function Copy-NsxIpSet { - <# - .SYNOPSIS - Copies NSX IP sets from Primary NSX manager to Secondary NSX Manager - - .DESCRIPTION - This Function Helps you to copy NSX Ip sets from One NSX Manager to Another - - .EXAMPLE - Copy-NsxIpSet -PrimaryNsxManager Nsx01.xyz.com -SecondaryNsxmanager Nsx02.xyz.com - - - - #> - [cmdletBinding()] - param ( - [parameter(Mandatory = $true)] - [string] $PrimaryNsxManager, - [parameter(Mandatory = $true)] - [string] $SecondaryNsxManager, - [parameter (Mandatory = $true)] - [pscredential] $credential - ) - begin - { - Connect-NsxServer $PrimaryNsxManager -DisableVIAutoConnect -Credential $credential - $NsxIpSets = @(Get-NsxIpSet) - Disconnect-NsxServer - } - process - { - Connect-NsxServer $SecondaryNsxManager -DisableVIAutoConnect -Credential $credential - Write-Verbose -Message "Syncing NsxIpSets from $PrimaryNsxManager to $SecondaryNsxManager" - foreach($Nsxipset in $NsxIpSets) - { - $IpSetExists = Get-NsxIpSet -Name $Nsxipset.Name -ErrorAction SilentlyContinue - if ($IpSetExists) - { - Write-Verbose -Message "Found the IPSet with Name $($NsxIpSet.Name)....Adding the Ip address" - try{ - Add-NsxIpSetMember -IPSet $IpSetExists -IPAddress $Nsxipset.value -ErrorAction stop -whatif - Write-Verbose -Message "updated the Ip set with name $($NsxIpset.name) and IpAddress $($NsxIpSet.value)" - } - catch{ - Write-Verbose -Message "Failed ! updating the Ip sets" - } - } - else{ - Write-Verbose -Message "Not Found ip set, Creating NsxIpSet $($NsxIpSet.Name)" - New-NsxIpSet -Name $NsxIpSet.Name -IPAddress $NsxIpSet.value - } - } - } -end { - Write-Verbose -Message "Sync Finished" -} -} - #Call Init function _init From 708f245aab42f54a98c75102a9c7ecea223f3f03 Mon Sep 17 00:00:00 2001 From: Jitendra Singh Date: Mon, 13 Jul 2020 08:58:57 +0530 Subject: [PATCH 3/4] added function Copy-NsxIpSet to examples folder --- Examples/Copy-NsxIpset.ps1 | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Examples/Copy-NsxIpset.ps1 diff --git a/Examples/Copy-NsxIpset.ps1 b/Examples/Copy-NsxIpset.ps1 new file mode 100644 index 00000000..487cec8e --- /dev/null +++ b/Examples/Copy-NsxIpset.ps1 @@ -0,0 +1,57 @@ +function Copy-NsxIpSet { + <# + .SYNOPSIS + Copies NSX IP sets from Primary NSX manager to Secondary NSX Manager + + .DESCRIPTION + This Function Helps you to copy NSX Ip sets from One NSX Manager to Another + + .EXAMPLE + Copy-NsxIpSet -PrimaryNsxManager Nsx01.xyz.com -SecondaryNsxmanager Nsx02.xyz.com + + + + #> + [cmdletBinding()] + param ( + [parameter(Mandatory = $true)] + [string] $PrimaryNsxManager, + [parameter(Mandatory = $true)] + [string] $SecondaryNsxManager, + [parameter (Mandatory = $true)] + [pscredential] $credential + ) + begin + { + Connect-NsxServer $PrimaryNsxManager -DisableVIAutoConnect -Credential $credential + $NsxIpSets = @(Get-NsxIpSet) + Disconnect-NsxServer + } + process + { + Connect-NsxServer $SecondaryNsxManager -DisableVIAutoConnect -Credential $credential + Write-Verbose -Message "Syncing NsxIpSets from $PrimaryNsxManager to $SecondaryNsxManager" + foreach($Nsxipset in $NsxIpSets) + { + $IpSetExists = Get-NsxIpSet -Name $Nsxipset.Name -ErrorAction SilentlyContinue + if ($IpSetExists) + { + Write-Verbose -Message "Found the IPSet with Name $($NsxIpSet.Name)....Adding the Ip address" + try{ + Add-NsxIpSetMember -IPSet $IpSetExists -IPAddress $Nsxipset.value -ErrorAction stop -whatif + Write-Verbose -Message "updated the Ip set with name $($NsxIpset.name) and IpAddress $($NsxIpSet.value)" + } + catch{ + Write-Verbose -Message "Failed ! updating the Ip sets" + } + } + else{ + Write-Verbose -Message "Not Found ip set, Creating NsxIpSet $($NsxIpSet.Name)" + New-NsxIpSet -Name $NsxIpSet.Name -IPAddress $NsxIpSet.value + } + } + } +end { + Write-Verbose -Message "Sync Finished" +} +} \ No newline at end of file From e710e4839cab98eaeba981f42df743c67c8ff2c1 Mon Sep 17 00:00:00 2001 From: Jitendra Singh Date: Mon, 13 Jul 2020 09:14:14 +0530 Subject: [PATCH 4/4] fixing space --- module/PowerNSX.psm1 | 1 + 1 file changed, 1 insertion(+) diff --git a/module/PowerNSX.psm1 b/module/PowerNSX.psm1 index fe3365c6..cd5468eb 100644 --- a/module/PowerNSX.psm1 +++ b/module/PowerNSX.psm1 @@ -36416,5 +36416,6 @@ function Copy-NsxEdge{ } end {} } + #Call Init function _init