1

I have the below code snippet that saves a array of ~90 devices to my string $report

$report = Get-ADComputer -Filter * -SearchBase 'OU=Boston, DC=someCompany, DC=com' | Select -ExpandProperty name

Now my issue is when I try to pass this array to my Invoke-RestMethod command

$headers=@{}
$headers.Add("Content-Type", "application/json")
$headers.Add("Authorization", "Bearer mykeyhere")
$response = Invoke-RestMethod -Uri "https://app.ninjarmm.com/v2/devices/search?q=$report[0]" -Method GET -Headers $headers

When I run the above code snippet, I would think that $response returns the result of my first array of $report, but what actually happens is that it returns back $response in the attached photo.

Help appreciated, thanks yall

nick asdf
  • 85
  • 4
  • In short: inside `"..."`, if you want to reference an expression that goes beyond a simple variable reference (e.g., `$var`), you need to enclose it in `$(...)` (e.g., `$($var[0])`). See the linked duplicate for details. – mklement0 Jul 26 '22 at 22:05

0 Answers0