0
votes

I am very new to powershell and I don't know what to do. I have the following code

$rest = Invoke-RestMethod -Uri https://blockchain.info/balance?active=3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP

$rest outputs:

$rest

3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP                                 
----------------------------------                                 
@{final_balance=150050010291; n_tx=20; total_received=150050010291}

How can i load the value of final_balance into a variable?

1
$var = $rest.3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP.final_balance ? - Theo
That returns an error "+ FullyQualifiedErrorId : MissingPropertyName" - user3801967
Pipe it to a Get-Member and see what it returns - Abraham Zinala

1 Answers

0
votes

Because of the fact that 3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP starts with a digit, you get an error when trying to access that property with the syntax $rest.3P.... What you can do instead, is wrapping it in a string like: $rest."3P..". See the below results:

> $rest = Invoke-RestMethod -Uri https://blockchain.info/balance?active=3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP

3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP
----------------------------------
@{final_balance=150050010291; n_tx=20; total_received=150050010291}

> $rest.3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP

ParserError:
Line |
   1 |  $rest.3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP
     |        ~
     | Missing property name after reference operator.

> $rest."3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP"

final_balance n_tx total_received
------------- ---- --------------
 150050010291   20   150050010291

> $final_balance = $rest."3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP".final_balance
> $final_balance

150050010291

In the terminal, you can press Ctrl+Space to get some autocomplete. Maybe this depends on the terminal, but if it works, it is really helpful for navigating into properties and getting recommendations.