-
Notifications
You must be signed in to change notification settings - Fork 89
adds function Copy-NsxIpset #627
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scope should be specified, so that ipsets are recreated appropraitely There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about inheritance? |
||
} | ||
} | ||
} | ||
end { | ||
Write-Verbose -Message "Sync Finished" | ||
} | ||
} |
There was a problem hiding this comment.
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