samedi 25 février 2017

Add-Member - ForEach Item Get Value From Other Info

I have a PowerShell script, which contain this methods:
1. Invoke-WebRequest: to get my json file.
2. Invoke-RestMethod: to get all ip information from (1).
I want to Add-Member which from $gip.city to each r.users information

Here is My Wrong Syntax:

$r = Invoke-WebRequest -Uri http://ift.tt/2lcpwkf | ConvertFrom-Json
$expip = $r.users  | select -expand ipaddress


ForEach($ips in $expip){

    $infoService = "http://ift.tt/2mj4Yvn"
    $gip = Invoke-RestMethod -Method Get -URI $infoService

    $r.users| Add-Member -NotePropertyName city -NotePropertyValue $gip.city -Force
}

#Resilt:
$r.users

When I run it, the new member 'City' is not contain any value, it shows this result:
http://ift.tt/2lcuFJ4




Aucun commentaire:

Enregistrer un commentaire