將 REST 與 PowerShell 物件一起使用以獲取和放置單個資料

獲取 REST 資料並儲存在 PowerShell 物件中:

$Post = Invoke-RestMethod -Uri "http://jsonplaceholder.typicode.com/posts/1"

修改你的資料:

$Post.title = "New Title"

將 REST 資料丟回

$Json = $Post | ConvertTo-Json
Invoke-RestMethod -Method Put -Uri "http://jsonplaceholder.typicode.com/posts/1" -Body $Json -ContentType 'application/json'