-
Notifications
You must be signed in to change notification settings - Fork 2
/
Export-vSE-NAT-Rules-from-vCD.ps1
48 lines (42 loc) · 1.89 KB
/
Export-vSE-NAT-Rules-from-vCD.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Run from a PowerCLI shell that has been logged into the vCloud Director instance using “Connect-CIServer -server url”
# and then run the script passing the following parameters:
# -edge or -e = The Edge Gateway Name
# Example:
# ./export-vse-nat-rules.ps1 -e “My vShield Edge”
param (
[parameter(Mandatory = $true, HelpMessage="Edge Gateway Name")][alias("-edge","e")][ValidateNotNullOrEmpty()][string[]]$egwname
)
#Set CSV filename
[string]$csvFile = $egwname + "vCD-backup.csv"
#Search EdgeGW
try {
$edgeView = Search-Cloud -QueryType EdgeGateway -Name $egwname -ErrorAction Stop | Get-CIView
} catch {
[System.Windows.Forms.MessageBox]::Show("Exception: " + $_.Exception.Message + " - Failed item:" + $_.Exception.ItemName ,"Error.",0,[System.Windows.Forms.MessageBoxIcon]::Exclamation)
Write-Warning "Edge Gateway with name $Edgeview not found"
Exit
}
$webclient = New-Object system.net.webclient
$webclient.Headers.Add("x-vcloud-authorization",$Edgeview.Client.SessionKey)
$webclient.Headers.Add("accept",$EdgeView.Type + ";version=5.1")
[XML]$EGWConfXML = $webclient.DownloadString($EdgeView.href)
$NATRules = $EGWConfXML.EdgeGateway.Configuration.EdgegatewayServiceConfiguration.NatService.Natrule
$Rules = @()
if ($NATRules){
$NATRules | ForEach-Object {
$NewRule = new-object PSObject -Property @{
Description = $_.Description;
AppliedOn = $_.GatewayNatRule.Interface.Name;
Type = $_.RuleType.ToUpper();
OriginalIP = $_.GatewayNatRule.OriginalIP;
OriginalPort = $_.GatewayNatRule.OriginalPort;
TranslatedIP = $_.GatewayNatRule.TranslatedIP;
TranslatedPort = $_.GatewayNatRule.TranslatedPort;
Protocol = $_.GatewayNatRule.Protocol;
Enabled = [string]$_.IsEnabled.ToLower();
ID = $_.ID;
}
$Rules += $NewRule
}
}
$Rules | Export-CSV -Path $csvFile -NoType