4 Replies Latest reply on Nov 9, 2018 6:51 AM by blaircotnam

    Script to get NSX Edge and Organization in csv

    blaircotnam Lurker



      I'm trying to put a script together to export the nsx edges (name, version) to their organization in csv format so, it will be easier to see which edges need to be upgraded based on the organization.  I was able to get all the edges and their version but, having issues linking it to the organization.  Can't seem to link the tenant and organization id's.  This is what i have so far.  Any assistance would be great.


      Connect-ViServer -Server $vcenter

      $reportPath = "C:\temp\upgradable-VSEs.csv"

      $report = @()


      $edges = Get-View -ViewType virtualmachine -Property Name,Config -Filter @{'Config.VAppConfig.Product[0].Name'='vShield Edge'} | % {

      $edge = '' | Select 'Name','Version'

      $edge.Name = $_.Name

      $edge.Version = $_.config.vappconfig.product[0].version

      $report += $edge



      $APIendpoint = "$myendpoint"

      $mysessionid = ($global:DefaultCIServers | Where { $_.Name -eq $APIendpoint }).SessionId

      $Headers = @{"x-vcloud-authorization" = $mysessionid; "Accept" = 'application/*+xml;version=' + '27.0'}

      $headers2 = @{"Accept"="application/*+xml;version=27.0"; "Authorization"="Basic $base64_decode"}

      $Request = "https://$APIendpoint/api/org/"

      $r = Invoke-RestMethod -Uri ($Request) -Headers $Headers -ContentType "application/xml"


      $orgs = search-cloud -QueryType Organization (can get org id from this list)


      (guess i need a foreach loop here which will loop through each edge and match the edge tenant id with the org id from the query above but, not sure where to get tenant id in the edge to match org id)


      $report | Export-Csv -Path $reportPath -NoTypeInformation -UseCulture


      How would i go about linking the edges to their org?  Sorry, fairly new to scripting.