This repository was archived by the owner on Sep 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathGet-NSXController.ps1
70 lines (62 loc) · 4.71 KB
/
Get-NSXController.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
function Get-NSXController {
<#
.SYNOPSIS Gathers NSX Controller details from NSX Manager
.DESCRIPTION Will inventory all of your controllers from NSX Manager
.NOTES Author: Chris Wahl, @ChrisWahl, WahlNetwork.com
.PARAMETER NSXManager
The FQDN or IP of your NSX Manager
.PARAMETER Username
The username to connect with. Defaults to admin if nothing is provided.
.PARAMETER Password
The password to connect with
.EXAMPLE
PS> Get-NSXController -NSXManager nsxmgr.fqdn -Username admin -Password password
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$true,Position=0)]
[String]$NSXManager,
[Parameter(Mandatory=$false,Position=1)]
[String]$Username = "admin",
[Parameter(Mandatory=$true)]
[String]$Password
)
Process {
### Ignore TLS/SSL errors
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
### Create authorization string and store in $head
$auth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($Username + ":" + $Password))
$head = @{"Authorization"="Basic $auth"}
### Connect to NSX Manager via API
$Request = "https://$NSXManager/api/2.0/vdn/controller"
$r = Invoke-WebRequest -Uri $Request -Headers $head -ContentType "application/xml" -ErrorAction:Stop
if ($r.StatusCode -eq "200") {Write-Host -BackgroundColor:Black -ForegroundColor:Green Status: Connected to $NSXManager successfully.}
[xml]$rxml = $r.Content
### Return the NSX Controllers
$global:nreport = @()
foreach ($controller in $rxml.controllers.controller)
{
$n = @{} | select Name,IP,Status,Version,VMName,Host,Datastore
$n.Name = $controller.id
$n.IP = $controller.ipAddress
$n.Status = $controller.status
$n.Version = $controller.version
$n.VMName = $controller.virtualMachineInfo.name
$n.Host = $controller.hostInfo.name
$n.Datastore = $controller.datastoreInfo.name
$global:nreport += $n
}
$global:nreport | ft -AutoSize
} # End of process
} # End of function