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 1 year, 5 months ago.

  • Author
  • #35233
    Profile photo of mc1903


    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 = @{

    $token = (Invoke-WebRequest -contenttype "application/x-www-form-urlencoded" -Uri "" -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

  • #35235
    Profile photo of Brendan DS
    Brendan DS

    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

    Thank you Brendan... I am so dumb!

You must be logged in to reply to this topic.