Advertisement
Guest User

Untitled

a guest
Mar 8th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. #Variables to be used within the script.
  2. [CmdletBinding()]
  3. $NSXUsername = "admin"
  4. $NSXPassword = "VMware1!"
  5. $uriP = "https://HQ-NSX-01a.nsx.gss"
  6.  
  7.  
  8. # Start time.
  9. $startclock = (Get-Date)
  10. Write-Host -BackgroundColor:Black -ForegroundColor:Green "Hello"
  11. Write-Host -BackgroundColor:Black -ForegroundColor:Green "This script will help you to automate a full NSX environment deployment"
  12. Write-Host -BackgroundColor:Black -ForegroundColor:Green "FULL NSX Tier Deployment for Single-VC is starting, This Deployment proccess will take an average of 60 min
  13. ========================================================================================
  14. "
  15.  
  16.  
  17.  
  18.  
  19. # Create NSX authorization string and store in $head and used in API Calls
  20. # $nsxcreds = New-Object System.Management.Automation.PSCredential $NSXUsername,$NSXPassword
  21. $auth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($NSXUsername + ":" + $NSXPassword))
  22. $head = @{"Authorization"="Basic $auth"}
  23.  
  24. # Allow untrusted SSL certs else will error out
  25. add-type @"
  26. using System.Net;
  27. using System.Security.Cryptography.X509Certificates;
  28. public class TrustAllCertsPolicy : ICertificatePolicy {
  29. public bool CheckValidationResult(
  30. ServicePoint srvPoint, X509Certificate certificate,
  31. WebRequest request, int certificateProblem) {
  32. return true;
  33. }
  34. }
  35. "@
  36. [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
  37.  
  38.  
  39. ################
  40. #Start of Script
  41. ################
  42.  
  43. ###########################################
  44. # Checking the current deployed NSX Version
  45. ###########################################
  46.  
  47. Write-Host -BackgroundColor:Black -ForegroundColor:Green " Checking the current deployed version of the NSX
  48. "
  49.  
  50.  
  51. $r = Invoke-WebRequest -Uri "$uriP/api/1.0/appliance-management/global/info" -Method:Get -Headers $head -ContentType "application/xml" -ErrorAction:Stop -TimeoutSec 60
  52. $nsxbn = ([xml]$r.Content).globalInfo.versionInfo.buildNumber
  53.  
  54. if ($nsxbn -match "2691049") {$nsxcv = "6.1.4"}
  55. elseif ($nsxbn -match "3102213") {$nsxcv = "6.1.5"}
  56. elseif ($nsxbn -match "3615148") {$nsxcv = "6.1.6"}
  57. elseif ($nsxbn -match "3949567") {$nsxcv = "6.1.7"}
  58. elseif ($nsxbn -match "2986609") {$nsxcv = "6.2.0"}
  59. elseif ($nsxbn -match "3300239") {$nsxcv = "6.2.1"}
  60. elseif ($nsxbn -match "3496286") {$nsxcv = "6.2.1a"}
  61. elseif ($nsxbn -match "3604087") {$nsxcv = "6.2.2"}
  62. elseif ($nsxbn -match "3638734") {$nsxcv = "6.2.2a"}
  63. elseif ($nsxbn -match "3755950") {$nsxcv = "6.2.2b"}
  64. elseif ($nsxbn -match "3979471") {$nsxcv = "6.2.3"}
  65. elseif ($nsxbn -match "4167369") {$nsxcv = "6.2.3a"}
  66. elseif ($nsxbn -match "4287432") {$nsxcv = "6.2.3b"}
  67. elseif ($nsxbn -match "4292526") {$nsxcv = "6.2.4"}
  68. elseif ($nsxbn -match "4818372") {$nsxcv = "6.2.5"}
  69. elseif ($nsxbn -match "4977495") {$nsxcv = "6.2.6"}
  70. elseif ($nsxbn -match "5007049") {$nsxcv = "6.3.0"}
  71. elseif ($nsxbn -match "5124716") {$nsxcv = "6.3.1"}
  72. else {
  73. Write-host -BackgroundColor:Black -ForegroundColor:Red " Unable to retrieve the NSX version, This is either due to the current version is unknown to this script or the NSX Manager is powered off. Please check and try again."
  74. exit
  75. }
  76.  
  77. Write-Host -BackgroundColor:Black -ForegroundColor:Green " Current version of NSX deployed and to be upgraded is $nsxcv
  78. "
  79.  
  80. <?xml version="1.0" encoding="UTF-8"?>
  81. <globalInfo>
  82. <currentLoggedInUser>admin</currentLoggedInUser>
  83. <versionInfo>
  84. <majorVersion>6</majorVersion>
  85. <minorVersion>1</minorVersion>
  86. <patchVersion>5</patchVersion>
  87. <buildNumber>3102213</buildNumber> <<<--- this is my match
  88. </versionInfo>
  89. </globalInfo>
  90.  
  91. Cannot convert value "{"currentLoggedInUser":"admin","versionInfo":{"majorVersion":"6","minorVersion":"1","patchVersion":"5","buildNumber":"3102213"}}"
  92. to type "System.Xml.XmlDocument". Error: "The specified node cannot be inserted as the valid child of this node, because the specified node is the wrong
  93. type."
  94. At C:UsersAdministratorDesktopScripts FolderNSX-Auto-Upgrade-Single.ps1:68 char:2
  95. + $nsxbn = ([xml]$r.Content).globalInfo.versionInfo.buildNumber
  96. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  97. + CategoryInfo : InvalidArgument: (:) [], RuntimeException
  98. + FullyQualifiedErrorId : InvalidCastToXmlDocument
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement