Advertisement
Guest User

Untitled

a guest
Jul 24th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.96 KB | None | 0 0
  1. SiteName : CGSM-Site
  2. NsxManagerFqdn : CGSM-NSX.nfv.gss
  3. NsxManagerUser : admin
  4. NsxManagerPassword : VMware1!
  5. vCenterFqdn : CGSM-VCSA.nfv.gss
  6. vCenterUser : administrator@vsphere.local
  7. vCenterPassword : VMware1!
  8. vCenterHostingNsxFqdn : CGSM-VCSA.nfv.gss
  9. vCenterHostingNsxUser : administrator@vsphere.local
  10. vCenterHostingNsxPassword : VMware1!
  11. vCenterHostingvCenterFqdn : CGSM-VCSA.nfv.gss
  12. vCenterHostingvCenterUser : administrator@vsphere.local
  13. vCenterHostingvCenterPassword : VMware1!
  14. PrimaryNsxManagerFQDN : NotUsed
  15. PrimaryNsxManagerUser : NotUsed
  16. PrimaryNsxManagerPassword : NotUsed
  17. vCenterRegisteredToPrimaryNsxFQDN : NotUsed
  18. vCenterRegisteredToPrimaryNsxUser : NotUsed
  19. vCenterRegisteredToPrimaryNsxPassword : NotUsed
  20. NsxController1IP : 192.168.4.61
  21. NsxController2IP : 192.168.4.62
  22. NsxController3IP : 192.168.4.63
  23. NsxControllersPassword : VMware1!VMware1!
  24.  
  25. SiteName : CGSR-Site
  26. NsxManagerFqdn : CGSR-NSX.nfv.gss
  27. NsxManagerUser : admin
  28. NsxManagerPassword : VMware1!
  29. vCenterFqdn : CGSR-VCSA.nfv.gss
  30. vCenterUser : administrator@vsphere.local
  31. vCenterPassword : VMware1!
  32. vCenterHostingNsxFqdn : CGSM-VCSA.nfv.gss
  33. vCenterHostingNsxUser : administrator@vsphere.local
  34. vCenterHostingNsxPassword : VMware1!
  35. vCenterHostingvCenterFqdn : CGSM-VCSA.nfv.gss
  36. vCenterHostingvCenterUser : administrator@vsphere.local
  37. vCenterHostingvCenterPassword : VMware1!
  38. PrimaryNsxManagerFQDN : CGSM-NSX.nfv.gss
  39. PrimaryNsxManagerUser : admin
  40. PrimaryNsxManagerPassword : VMware1!
  41. vCenterRegisteredToPrimaryNsxFQDN : CGSM-VCSA.nfv.gss
  42. vCenterRegisteredToPrimaryNsxUser : administrator@vsphere.local
  43. vCenterRegisteredToPrimaryNsxPassword : VMware1!
  44. NsxController1IP : 192.168.4.61
  45. NsxController2IP : 192.168.4.62
  46. NsxController3IP : 192.168.4.63
  47. NsxControllersPassword : VMware1!VMware1!
  48.  
  49. #region ######### - 2nd Sub-Sub-Section - SubSubSectionName: CheckIfNoNsxIsInUse.
  50.  
  51. ###########################################
  52. ####### Start of SubSubSection ######
  53. ###########################################
  54.  
  55. #SubSection Description: This SubSubsection will check and validate the info gathered from the vSphere-NSX-Required-Info.csv file with respect to the IP/FQDN connectivity as well as the credentials if the NSX is Not in use.
  56. #--------------------------------------------------------------------------------------------------------
  57.  
  58. Write-Host -BackgroundColor:Black -ForegroundColor:Gray " NSX-v is not used, Checking credentials and connection to vCenter Server only."
  59.  
  60. Foreach ($Line in $vSphereNSXEnvironmentInfo) {
  61.  
  62. Write-Host -BackgroundColor:Black -ForegroundColor:Gray " Working on Site " $Line.SiteName " For " $Line.vCenterFqdn "."
  63.  
  64. #region ££££££££££££ - 1st Sub-Sub-Sub-Section - SubSubSubSectionName: CheckConnectivity.
  65.  
  66. ###########################################
  67. ####### Start of SubSubSection ######
  68. ###########################################
  69.  
  70. #SubSubSubSection Description: This SubSubSubsection will check Connectivity.
  71. #-------------------------------------------------------------------------
  72.  
  73. #Check Connectivity for vCenter Servers in each provided site in the vSphere-NSX-Required-Info.csv
  74.  
  75.  
  76. #Test Connection for the endpoint and the hosting endpoint over port 22 and 443.
  77. Write-Host -BackgroundColor:Black -ForegroundColor:Gray " Checking connection over port 22 and 443."
  78.  
  79. #Create an array and add 22 and 443 in it to loop over it to make it easier for the code instead of writing the code twice once for 22 and another for 443
  80. $RequiredPorts = @("22","443")
  81. Foreach ($Port in $RequiredPorts) {
  82. #Create an array with the FQDN of the End point and check of the hosting vCenter is the same and if not then add it to the array.
  83. #Reason of creating this array is to minimize the code by running a loop for this array rather than writing the code 4 times once for each endpoint.
  84. $EndPoints = @()
  85. $EndPoints += $Line.vCenterFqdn
  86. If ($Line.vCenterFqdn -NE $Line.vCenterHostingvCenterFqdn) {$EndPoints += $Line.vCenterHostingvCenterFqdn}
  87. Foreach ($Target in $EndPoints) {
  88. $TestConnection = Test-NetConnection -Port $Port -ComputerName $Target
  89. If ($TestConnection.PingSucceeded -Eq "True") {
  90. Write-Host -BackgroundColor:Black -ForegroundColor:DarkYellow " Connection to "$Target " over port " $Port " is successful."
  91. }
  92. Else {
  93. Write-Host -BackgroundColor:Black -ForegroundColor:Red " Connection to "$Target " over port " $Port " is not successful."
  94. Write-Host -BackgroundColor:Black -ForegroundColor:Red " Please check connectivity to endpoints and try again."
  95. start-sleep 5
  96. Break
  97. }
  98. }
  99. }
  100.  
  101.  
  102. ###########################################
  103. ####### End of SubSubSubSection #####
  104. ###########################################
  105.  
  106. #----------------------------------------------
  107.  
  108. #endregion
  109.  
  110. #-----------------------------------------
  111.  
  112. #region ££££££££££££ - 2nd Sub-Sub-Sub-Section - SubSubSubSectionName: CheckValidityOfUsername&Password.
  113.  
  114. ###########################################
  115. ####### Start of SubSubSection ######
  116. ###########################################
  117.  
  118. #SubSubSubSection Description: This SubSubSubsection will check Validity of Username and Passwords.
  119. #-------------------------------------------------------------------------
  120.  
  121. #Check validity of usernames and passwords for each NSX/vCneter EndPoint in each provided site in the vSphere-NSX-Required-Info.csv
  122.  
  123. Write-Host -BackgroundColor:Black -ForegroundColor:Gray " Checking gathered Username and Passwords for all vCenter Servers."
  124.  
  125.  
  126. #Create an HashTable with the FQDN, Username and Password for each Endpoint and then add the HashTable to an Array Variable to have all Endpoints info.
  127. #Reason of creating this array is to minimize the code by running a loop for this array rather than writing the code once for each endpoint.
  128.  
  129. #Create the Variable, Note that the Hashtable will be created each time the tool go to another endpoint to delete the priviouse info of the priviouse endpoint.
  130. $EndPointsArray = @()
  131.  
  132. #1- Add Working vCenter Server to the HashTable
  133. $EndPointsHashTable = @{}
  134. $URL = "https://" + $Line.vCenterFqdn + "/rest/com/vmware/cis/session"
  135. $EndPointsHashTable.add("Description", "vCenter")
  136. $EndPointsHashTable.add("EndPoint", $Line.vCenterFqdn)
  137. $EndPointsHashTable.add("URI", $URL)
  138. $Header = vCenterAuthurization -Username $Line.vCenterUser -Password $Line.vCenterPassword
  139. $EndPointsHashTable.add("Header", $Header)
  140. $EndPointsArray += $EndPointsHashTable
  141.  
  142. #2- Add vCneter Server VM Hosting vCenter Server to the HashTable if exists.
  143. If ($Line.vCenterFqdn -NE $Line.vCenterHostingvCenterFqdn) {
  144. $URL = "https://" + $Line.vCenterHostingvCenterFqdn + "/rest/com/vmware/cis/session"
  145. $EndPointsHashTable.add("Description", "vCenter")
  146. $EndPointsHashTable.add("EndPoint", $Line.vCenterHostingvCenterFqdn)
  147. $EndPointsHashTable.add("URI", $URL)
  148. $Header = vCenterAuthurization -Username $Line.vCenterHostingvCenterUser -Password $Line.vCenterHostingvCenterPassword
  149. $EndPointsHashTable.add("Header", $Header)
  150. $EndPointsArray += $EndPointsHashTable
  151. }
  152.  
  153.  
  154. #Run the llop for the gathered info in the EndPointsArray Array Variable and validate the Username and Password.
  155. Foreach ($EndPoint in $EndPointsArray) {
  156.  
  157. #Check if it is a Controller and if yes then use the Push-SSH.
  158. If ($EndPoint.Description -Eq "Controller") {
  159. $TestCredentials = New-SSHSession -ComputerName $EndPoint.URI -Credential $EndPoint.Header -AcceptKey
  160. If ($TestCredentials) {Write-Host -BackgroundColor:Black -ForegroundColor:DarkYellow " Username and Password for " $EndPoint.URI " are successful."}
  161. Else {
  162. Write-Host -BackgroundColor:Black -ForegroundColor:Red " Provided Username and Password for " $EndPoint.URI " are incorrect."
  163. Write-Host -BackgroundColor:Black -ForegroundColor:Red " Please check Username and Password and try again."
  164. start-sleep 5
  165. Break
  166. }
  167. }
  168.  
  169. #Run the validation for the rest normally as there will be nothing else that will need to use Push-SSH rathere than Invoke-WebRequest.
  170. $TestCredentials = Invoke-WebRequest -Uri $EndPoint.URI -Method Post -Headers $head
  171. If ($TestCredentials.StatusCode -Eq 200) {Write-Host -BackgroundColor:Black -ForegroundColor:DarkYellow " Username and Password for " $EndPoint.URI " are successful."}
  172. Else {
  173. Write-Host -BackgroundColor:Black -ForegroundColor:Red " Provided Username and Password for " $EndPoint.URI " are incorrect."
  174. Write-Host -BackgroundColor:Black -ForegroundColor:Red " Please check Username and Password and try again."
  175. start-sleep 5
  176. Break
  177. }
  178. }
  179.  
  180.  
  181. ###########################################
  182. ####### End of SubSubSubSection #####
  183. ###########################################
  184.  
  185. #----------------------------------------------
  186.  
  187. #endregion
  188.  
  189. #-----------------------------------------
  190.  
  191. #region ££££££££££££ - 3rd Sub-Sub-Sub-Section - SubSubSubSectionName: CheckHostingvCenterServers.
  192.  
  193. ###########################################
  194. ####### Start of SubSubSection ######
  195. ###########################################
  196.  
  197. #SubSubSubSection Description: This SubSubSubsection will Check and validate the hosting vCenterServer.
  198. #-------------------------------------------------------------------------
  199.  
  200. #Check if the Hosting vCenter Server are correct.
  201.  
  202. Write-Host -BackgroundColor:Black -ForegroundColor:Gray " Validating Hosting vCenter for vCenter VM"
  203.  
  204. #Second will check if vCenterHostingvCenterFqdn field is not set to NotUsed which would indicate that there are are a Hosting vCenter.
  205. #If vCenterHostingvCenterFqdn is set to a value other than NotUsed, Connect and try to locate the NSX Manager VM.
  206. #If vCenterHostingvCenterFqdn is set to NotUsed then Connect to the Working vCenter and Locate the NSX Manaver VM.
  207. If ($Line.vCenterHostingvCenterFqdn -NE "NotUsed") {
  208.  
  209. Write-Host -BackgroundColor:Black -ForegroundColor:Gray " Another hosting vCenter for vCenter is detected in csv file, confirmting info."
  210.  
  211. #At this point there is a hosting vCenter to the NSX, Connect and try to locate.
  212. $HostingvCenterforWorkingvCenterConnection = Connect-VIServer -Server $Line.vCenterHostingvCenterFqdn -User $Line.vCenterHostingvCenterUser -Password $Line.vCenterHostingvCenterPassword -Force -WarningAction SilentlyContinue -InformationAction Ignore -ErrorAction SilentlyContinue
  213. If ($HostingvCenterforWorkingvCenterConnection) {
  214. #Convert Working NSX Manager FQDN to IP to be used in locating the VM.
  215. $vCenterIpConverted = [System.Net.Dns]::GetHostAddresses($Line.vCenterFqdn)
  216. $LocatevCenterVM = Get-VM -Server $HostingvCenterforWorkingvCenterConnection | Where-Object -FilterScript { $_.Guest.Nics.IPAddress -contains "$vCenterIpConverted" }
  217. Disconnect-VIServer -Server $HostingvCenterforWorkingvCenterConnection -Force -WarningAction SilentlyContinue -InformationAction SilentlyContinue -ErrorAction SilentlyContinue -Confirm:$false
  218. If ($LocatevCenterVM) {
  219. Write-Host -BackgroundColor:Black -ForegroundColor:DarkYellow " " $Line.vCenterFqdn " is confirmed to be Hosted on " $Line.vCenterHostingvCenterFqdn "."
  220. }
  221. Else {
  222. Write-Host -BackgroundColor:Black -ForegroundColor:Red " " $Line.vCenterFqdn " VM could not be found on " $Line.vCenterHostingvCenterFqdn "."
  223. Write-Host -BackgroundColor:Black -ForegroundColor:Red " Data Provided are incorrect, please check and try again."
  224. start-sleep 5
  225. Break
  226. }
  227. }
  228. Else {
  229. Write-Host -BackgroundColor:Black -ForegroundColor:Red " Unable to connect to " $Line.vCenterHostingvCenterFqdn "."
  230. Write-Host -BackgroundColor:Black -ForegroundColor:Red " Please check and try again."
  231. start-sleep 5
  232. Break
  233. }
  234. }
  235. Else {
  236.  
  237. Write-Host -BackgroundColor:Black -ForegroundColor:Gray " No additional hosting vCenter is detected in csv file, confirmting info."
  238.  
  239. #At this point there are no additional hosting vCenter are detected, which means that the NSX is hosted on vCenterFqdn, Connect and try to locate..
  240. $HostingvCenterforWorkingvCenterConnection = Connect-VIServer -Server $Line.vCenterFqdn -User $Line.vCenterUser -Password $Line.vCenterPassword -Force -WarningAction SilentlyContinue -InformationAction Ignore -ErrorAction SilentlyContinue
  241. If ($HostingvCenterforWorkingvCenterConnection) {
  242. #Convert Working NSX Manager FQDN to IP to be used in locating the VM.
  243. $vCenterIpConverted = [System.Net.Dns]::GetHostAddresses($Line.vCenterFqdn)
  244. $LocateNsxVM = Get-VM -Server $HostingvCenterforWorkingvCenterConnection | Where-Object -FilterScript { $_.Guest.Nics.IPAddress -contains "$vCenterIpConverted" }
  245. Disconnect-VIServer -Server $HostingvCenterforWorkingvCenterConnection -Force -WarningAction SilentlyContinue -InformationAction SilentlyContinue -ErrorAction SilentlyContinue -Confirm:$false
  246. If ($LocateNsxVM) {
  247. Write-Host -BackgroundColor:Black -ForegroundColor:DarkYellow " " $Line.vCenterFqdn " is confirmed to be Hosted on " $Line.vCenterFqdn "."
  248. }
  249. Else {
  250. Write-Host -BackgroundColor:Black -ForegroundColor:Red " " $Line.vCenterFqdn " VM could not be found on " $Line.vCenterFqdn "."
  251. Write-Host -BackgroundColor:Black -ForegroundColor:Red " Data Provided are incorrect, please check and try again."
  252. start-sleep 5
  253. Break
  254. }
  255. }
  256. Else {
  257. Write-Host -BackgroundColor:Black -ForegroundColor:Red " Unable to connect to " $Line.vCenterFqdn "."
  258. Write-Host -BackgroundColor:Black -ForegroundColor:Red " Please check and try again."
  259. start-sleep 5
  260. Break
  261. }
  262.  
  263. }
  264. #----------------------------------------------------------------
  265.  
  266.  
  267. ###########################################
  268. ####### End of SubSubSubSection #####
  269. ###########################################
  270.  
  271. #----------------------------------------------
  272.  
  273. #endregion
  274.  
  275. #-----------------------------------------
  276.  
  277.  
  278. } #End of rht Foreach Loop started at the begining.
  279.  
  280. Write-Host -BackgroundColor:Black -ForegroundColor:DarkGreen " All dtat in vSphere-NSX-Required-Info.csv file was validated."
  281.  
  282. ###########################################
  283. ####### End of SubSubSection ######
  284. ###########################################
  285.  
  286. #----------------------------------------------
  287.  
  288. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement