0

Need your help on this. I cannot get the right way of passing the variable to the URL. I am receiving errors.

**$SRnumber** = Read-Host "Enter SR Number"
    #144152
    $requestDescr = 
      Invoke-WebRequest 'https://test.com/api/v3/requests/**$SRnumber**?TECHNICIAN_KEY=ABCDEDFGHIJKLMNOPQRSTUVWXYZ' |
       ConvertFrom-Json  |
        Select -expand request

Error im receiving is below,

Invoke-WebRequest : {"response_status":{"status_code":4000,"messages":[{"status_code":4007,"type":
"failed"}],"status":"failed"}}
At line:4 char:3

1 Answers1

1

To use interpolated strings in powershell, you need to use double-quotes:

$SRnumber = Read-Host "Enter SR Number"
#144152
$requestDescr = Invoke-WebRequest "https://test.com/api/v3/requests/$SRnumber?TECHNICIAN_KEY=ABCDEDFGHIJKLMNOPQRSTUVWXYZ" |
    ConvertFrom-Json | Select -expand request
Palle Due
  • 5,929
  • 4
  • 17
  • 32