Brocade Fibre Channel Networking Community

BNA REST API Connection with PowerShell

  • 1.  BNA REST API Connection with PowerShell

    Posted 03-13-2020 05:35 PM

    I would like to automate to collect Brocade SAN information with BNA REST API.

    We are running BNA 14.4.4. I can use Advance RestClient to connect BNA REST API without any issues. I am trying to use PowerShell Invoke-RestMethod command to script. I can connect with PowerShell command, but I can't find the WStoken. The WStoken is required for subsequent REST API commands.

    Does anyone used PowerShell to connect REST-API? I know there is Python scripts available.

    This is what I have so far...

    PS C:> $headers = @{
    'WSusername'='******'
    'WSpassword'='******'
    'Accept'='application/vnd.brocade.networkadvisor+json;version=v1'
    'Content-Type'='application/json'
    }
    PS C:> $URI='http://xx.xxx.x.xx/rest/login'
    PS C:> $response = Invoke-RestMethod -Uri $URI -Headers $headers -Method Post -SessionVariable bnasession

    PS C:> $response

    serverName serverIp version
    ---------- -------- -------
    AAAAAAAA xx.xxx.x.xx 14.4.4

    PS C:> $bnasession

    Headers : {[WSpassword, *****], [WSusername, ******], [Content-Type, application/json], [Accept,
    application/vnd.brocade.networkadvisor+json;version=v1]}
    Cookies : System.Net.CookieContainer
    UseDefaultCredentials : False
    Credentials :
    Certificates :
    UserAgent : Mozilla/5.0 (Windows NT; Windows NT 10.0; en-US) WindowsPowerShell/5.1.17763.771
    Proxy :
    MaximumRedirection : -1



    ------------------------------
    -Thanks
    ------------------------------