blaircotnam
Contributor
Contributor

Script to get NSX Edge and Organization in csv

Hi,

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.

Thanks,

-b

Tags (3)
0 Kudos
5 Replies
blaircotnam
Contributor
Contributor

I was able to match the org id with the edge tenant id - i was doing the wrong request so, fixed that to get the edges.  Now, i have to figure how i'm going to get all the info into a cvs (org name, edge name, edge version).

$Request = "https://$APIendpoint/network/edges"

foreach ($edge in $r.pagedEdgeList.edgePage.edgeSummary)

{

   $orgs | where {$_.Id.replace("urn:vcloud:org:","") -eq $edge.tenantId} | Select -Property Name

}

Any pointers on that based on the code i have would be appreciated.

Thanks..

0 Kudos
blaircotnam
Contributor
Contributor

I was able to resolve this and get the script to output orgname, edgename, edgeversion, edgeObjectID to a cvs file using api calls to vcd 8.20

If anyone is interested i can post the code for reference.

Thanks,

-b

0 Kudos
LucD
Leadership
Leadership

Nice, but even better would be to submit the script to the PowerCLI Example Scripts repo.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
blaircotnam
Contributor
Contributor

Will do, thanks LucD...

0 Kudos
Gjohar
Contributor
Contributor

I don't know if you are still seeking the solution or not. I just want to mention in case-

 

https://www.vcnotes.in/2019/10/how-to-get-complete-list-of-nsx-edges.html

0 Kudos