-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNsxSynchronisation.ps1
120 lines (102 loc) · 4.81 KB
/
NsxSynchronisation.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<#
.DESCRIPTION
This script takes input from the user to syncronize a source and destination NSX Mgr
with DFW rules to be specified in a section
.NOTES
File Name:NsxSynchronization.ps1
.OPTIONS
None yet, but should also be able to be called from script/task
.LINK
Github to be created https://github.com/Paikke/NsxSynchronization
.DEPENDENCIES
VMware.PowerCLI
PowerNSX
NSxObjectCapture.ps1 taken from DiagramNSX; Changed the export from user profile to the current location
.INPUT
Requires user interaction during script for NSX connection parameters
.OUTPUT
Export settings in zipped XML report.
To be included - Log file.
#>
# Settings
$logon = "Yes" # Do we want the script to log Yes or No
$logFile = "NsxSynchronization.log" # Log File location
# Dot Source Functions.ps1
. "$PSScriptRoot\Functions.ps1"
# Parameter for NsxObjectCapture.ps1 is Connection
#########
# Run Baby Run
#########
## Init Log with current time
If ($logon -eq "Yes") { Write-Log "Starting engines" }
# Get input from user about
# NSX Manager
$nsxManager = Read-Host ("Source vCenter connected to NSX (FQDN/IP)")
If(!($nsxManager)){
# no manager throw error and exit
If ($logon -eq "Yes") { Write-Log "[ERROR] Asked user about vCenter/NSX manager. Got no usable response: $nsxManager" }
throw "Asked user about vCenter/NSX manager. Got no usable response: $nsxManager"
}
If ($logon -eq "Yes") { Write-Log "Asked user about NSX manager. Got response: $nsxManager" }
# User
$nsxUser = Read-Host ("SSO NSX User to connect and with permissions to read")
If(!($nsxUser)){
# no user throw error and exit
If ($logon -eq "Yes") { Write-Log "[ERROR] Asked user about SSO NSX user. Got no usable response: $nsxUser" }
throw "Asked user about SSO NSX User. Got no usable response: $nsxUser"
}
If ($logon -eq "Yes") { Write-Log "Asked user about SSO NSX User. Got response: $nsxUser" }
# Pass
# Will not log password
$nsxPass = Read-Host ("SSO user Password to connect")
If(!($nsxPass)){
# no Pass throw error and exit
If ($logon -eq "Yes") { Write-Log "[ERROR] Asked user about password. Got no usable response: <not logged>" }
throw "Asked user about password. Got no usable response: $nsxPass"
}
If ($logon -eq "Yes") { Write-Log "Asked User about NSX Pass. Got response: <input not logged>" }
# Trust certificate?
# Open Connection
# Use as -connection $NSXConnection is the remainder of commands
If ($logon -eq "Yes") { Write-Log "Opening connection to NSX Manager" }
$NSXConnection = Connect-NsxServer -vCenterServer $nsxManager -username $nsxUser -Password $nsxPass #-DefaultConnection:$false
# Use this in connection to NsxObjectCapture.ps1
# Again dot source
If ($logon -eq "Yes") { Write-Log "Running Export on Source NSXConnection" }
. ./NsxObjectCapture.ps1 -Connection $NSXConnection
If ($logon -eq "Yes") { Write-Log "Done with Source NSXConnection" }
If ($logon -eq "Yes") { Write-Log "Get Destination NSXConnection" }
$nsxManagerDst = Read-Host ("Destination vCenter connected to NSX (FQDN/IP)")
If(!($nsxManagerDst)){
# no manager throw error and exit
If ($logon -eq "Yes") { Write-Log "[ERROR] Asked user about vCenter/NSX manager. Got no usable response: $nsxManager" }
throw "Asked user about vCenter/NSX manager. Got no usable response: $nsxManagerDst"
}
If ($logon -eq "Yes") { Write-Log "Asked user about NSX manager. Got response: $nsxManagerDst" }
# User
$nsxUserDst = Read-Host ("SSO NSX User to connect and with permissions to add")
If(!($nsxUserDst)){
# no user throw error and exit
If ($logon -eq "Yes") { Write-Log "[ERROR] Asked user about SSO NSX user. Got no usable response: $nsxUserDst" }
throw "Asked user about SSO NSX User. Got no usable response: $nsxUserDst"
}
If ($logon -eq "Yes") { Write-Log "Asked user about SSO NSX User. Got response: $nsxUserDst" }
# Pass
# Will not log password
$nsxPassDst = Read-Host ("SSO user Password to connect")
If(!($nsxPassDst)){
# no Pass throw error and exit
If ($logon -eq "Yes") { Write-Log "[ERROR] Asked user about password. Got no usable response: <not logged>" }
throw "Asked user about password. Got no usable response: $nsxPassDst"
}
If ($logon -eq "Yes") { Write-Log "Asked User about NSX Pass. Got response: <input not logged>" }
# Trust certificate?
# Open Connection
# Use as -connection $NSXConnection is the remainder of commands
If ($logon -eq "Yes") { Write-Log "Opening connection to Destination NSX Manager" }
$NSXConnectionDst = Connect-NsxServer -vCenterServer $nsxManagerDst -username $nsxUserDst -Password $nsxPassDst #-DefaultConnection:$false
# Use this in connection to NsxObjectImport.ps1
# Again dot source
If ($logon -eq "Yes") { Write-Log "Running Import on Destination NSXConnection" }
. ./NsxObjectImport.ps1 -Connection $NSXConnectionDst -CaptureBundle $ExportFile
#EOF