简体   繁体   English

示例Power-Shell脚本以从REST API读取值

[英]sample power-shell script to read values from REST API

I need a sample powershell script to read values/single value from a given RESTFul API. 我需要一个示例powershell脚本来从给定的RESTFul API中读取值/单个值。 Here is the URL of sample restful URL 这是示例静态URL的URL

http://dummy.restapiexample.com/ http://dummy.restapiexample.com/

Below is the one I tried.But instead of count I wanted to get some employees data. 下面是我尝试过的方法,但我想获得一些员工数据而不是计数。

<!-- begin snippet: js hide: false console: true babel: false -->
$response = Invoke-RestMethod 'http://dummy.restapiexample.com/api/v1/employees'
$employees = $response.items.Count;
Write-Host "employees=$employees";
Output:
employees= 272
$response = Invoke-RestMethod 'http://dummy.restapiexample.com/api/v1/employees'
foreach($item in $response){
    Write-Host "$item"
}

this will display each record.. 这将显示每个记录。

Invoke-RestMethod 'http://dummy.restapiexample.com/api/v1/employees'
foreach($item in $response){
    Write-Host $item.employee_name
}

this will display only names. 这将仅显示名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM