Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

adds function Copy-NsxIpset #627

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions Examples/Copy-NsxIpset.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
function Copy-NsxIpSet {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add any version or module requirements at the top here. Maybe take a look at the following as an example
https://github.com/vmware/powernsx/blob/master/Examples/EnableFirewallRuleLogging.ps1

Also please add Author details, contact information and script/function/cmdlet versioning

<#
.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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does it handle different credentials for the primary and secondary managers?

)
begin
{
Connect-NsxServer $PrimaryNsxManager -DisableVIAutoConnect -Credential $credential
$NsxIpSets = @(Get-NsxIpSet)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the primary one has both global and universal ipsets? is the intention that all will be copied?

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scope should be specified, so that ipsets are recreated appropraitely

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about inheritance?

}
}
}
end {
Write-Verbose -Message "Sync Finished"
}
}