title: Powershell passing element of array as argument
body: <p>I am a PowerShell novice and I am stuck :(. I wrote what was I thought a simple script to just add a list of users to an AD group. But unfortunately it doesn´t work. I have got the correct objectId in an array but then when I try to pass it as an argument it fails. Does anyway find a way forward? I feel it is something very simple but I have tried a lot of different things and well as it says I am stuck</p>
  <p>Added some clarifications below code segment</p>
  <pre><code>$UsersToAdd = @(
      'user@domain.com',
      'user2@domain.com'
  )
  $ParentGroup = &quot;DomainGroupX&quot;
  
  ForEach ($User in $UsersToAdd)
  {
      $UserId = az ad user list --upn $User --query [].objectId
      $test = $UserId[1]
      If ($UserId.count -le 1) { echo &quot;$User not found&quot; }else {
          az ad group member add --group $ParentGroup --member-id $test
      }
  }
  </code></pre>
  <p>The problem is in this line: az ad group member add --group $ParentGroup --member-id $test</p>
  <p>this $test item is an array with one single ObjectId in it, something like this
  [ &quot;sdjasddheiieyieyie&quot;]</p>
  <p>But now It fails when i try to pass it whereas the below does work
  az ad group member add --group $ParentGroup --member-id &quot;sdjasddheiieyieyie&quot;</p>
  <p>Thank you!!</p>