How to extract the string from a NoteProperty returned within a PSCustomObject..

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of mc1903 mc1903 7 months, 2 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #35233
    Profile photo of mc1903
    mc1903
    Participant

    Hi,

    I am struggling to extract the string from a NoteProperty returned within a PSCustomObject.

    I am looking to query a API from Cisco (Cisco PSIRT openVuln). I have managed to authenticate using the following code:

    $client_id = "client_id-removed"
    $client_secret = "client_secret_removed"

    $tokenParams = @{
    client_id=$client_id;
    client_secret=$client_secret;
    grant_type="client_credentials"
    }

    $token = (Invoke-WebRequest -contenttype "application/x-www-form-urlencoded" -Uri "https://cloudsso.cisco.com/as/token.oauth2" -Method POST -Body $tokenParams)

    $token.AllElements | get-member

    Which (obviously with the correct client_id & client_secret values) returns the API session token in a NoteProperty as a string, like this:

    TypeName: System.Management.Automation.PSCustomObject

    Name MemberType Definition
    ---- ---------- ----------
    Equals Method bool Equals(System.Object obj)
    GetHashCode Method int GetHashCode()
    GetType Method type GetType()
    ToString Method string ToString()
    innerHTML NoteProperty string innerHTML=...
    innerText NoteProperty string innerText={"access_token":"Vo5MtBD7AvgcdwF3U5hwj83wskiw","token_type":"Bearer","expires_in":3599}
    outerHTML NoteProperty string outerHTML=...
    outerText NoteProperty string outerText={"access_token":"Vo5MtBD7AvgcdwF3U5hwj83wskiw","token_type":"Bearer","expires_in":3599}
    tagName NoteProperty string tagName=HTML

    I am stuck on how to extract InnerText as variables (access_token, token_type, etc)

    I would appreciate any help you can offer.

    Many Thanks
    Martin

    #35235
    Profile photo of Brendan DS
    Brendan DS
    Participant

    Hi Martin,

    I believe you should be able to assign the contents of InnerText as such

     $Varname = $token.AllElements.innerText 

    After that point you should be able to split the contents by ",".

    Hope that helps.

    #35236
    Profile photo of mc1903
    mc1903
    Participant

    Thank you Brendan... I am so dumb!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.