I am trying to extract the IP addresses from a particular security group using Power Shell API
Below is the power shell script I am using. Its not working
Any inputs what i need to change in the script to make it work.
$NSXUsername = "admin"
$NSXPassword = "VMware1!"
$auth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($NSXUsername+":"+$NSXPassword))
$head = @{"Authorization"="Basic $auth"}
$uri = "https://192.168.110.15"
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
Invoke-RestMethod -uri "$uri/api/2.0/services/securitygroup/securitygroup-16/translation/ipaddresses" -Body $body -Method:Get $head
If you are looking a way to document membership of VMs in Security Groups and its IP addresses, you can reuse this PowerNSX script
GitHub - tonysangha/PowerNSX-DFW2Excel: Export the NSX for vSphere Distributed Firewall to MS Excel
You can do this with 1 line using PowerNSX
Get-NsxSecurityGroup -Name blah | Get-NsxSecurityGroupEffectiveIpAddress
This is a fair answer, but I find when using this pipeline I only get 4 results - so for instance I have a security group with 6 ipsets - any ideas how I can show all 6? I.e. a complete listing?
Thanks
check out the nsx-powerops
The excel creation is better than the original one posted (it was amalgamated)
I wrote a function in powershell that uses an encryption key (saved in a locked down directory specific to the user running it) to decrypt encrypted usernames and passwords to pass into credential objects which make the neccesary connection calls to nsx/vmware - as I found the excel (which is great dont get me wrong) a little boring to wait to complete. so just schedule it an let it do it's thing.