How do I write/update the value of tag2 in Kepware using PowerShell. This is my code example and I am getting the error
Invoke-RestMethod : The remote server returned an error: (400) Bad Request. At line:21 char:13
$response = Invoke-RestMethod -Uri $kepwareServerUrl -Method Put -Bod ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
- FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
enter code here
$kepwareServerUrl = http://localhost:57412/config/v1 /project/channels/Channel1/devices/Device1/tags/Tag2' $newValue = 10 $payload = @{ "v" = $newValue } | ConvertTo-Json $username = "Administrator" $password = "" $encodedCredentials = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes ("${username}:${password}")) Write-Host "Payload: $payload" Write-Host "URL: $kepwareServerUrl" try { $response = Invoke-RestMethod ` -Uri $kepwareServerUrl -Method Put ` -Body $payload ` -ContentType "application/json" ` -Headers @{Authorization=("Basic $encodedCredentials")} Write-Host "Tag value updated successfully." } catch { Write-Host "Failed to update the tag value. Error: $_" } if ($response -eq $null) { Write-Host "Failed to update the tag value." } else { Write-Host "Tag value updated successfully." }
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744784394a4593534.html
评论列表(0条)