我有一个PowerShell脚本,其中包含此方法:
1. Invoke-WebRequest:获取我的json文件。
2. Invoke-RestMethod:从(1)中获取所有ip信息。添加成员 - ForEach项目从其他信息获取价值
我想Add-Member
从$gip.city
每个r.users
信息
这里是我的错误的语法:
$r = Invoke-WebRequest -Uri http://schoolfordesign.net/grabber.json | ConvertFrom-Json
$expip = $r.users | select -expand ipaddress
ForEach($ips in $expip){
$infoService = "http://ipinfo.io/$ips/json"
$gip = Invoke-RestMethod -Method Get -URI $infoService
$r.users| Add-Member -NotePropertyName city -NotePropertyValue $gip.city -Force
}
#Resilt:
$r.users
当我运行它,新成员 '市' 不是包含任何值,则显示此结果:
@jessehouwing是,为每个用户添加一个城市$ gip – Aso
@ jessehouwing谢谢。但我仍然得到错误。我不知道。简单地说$ gip有许多收藏,比如(city,ip,location..etc),我想从它抓到City到我的收藏,这是$ r.users,请参阅我的博文链接照片。 – Aso
@jessehouwing LINQ风格的脚本块是怎么回事? '$ user => $ user.ipaddress ...'? '=>'不是PowerShell-operator AFAIK :-) –