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

1
  • 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. Commented Jul 26, 2022 at 22:05

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.