title: Powershell: A positional parameter cannot be found that accepts argument "xxx"
body: <p>I am trying to understand what this error actually means. So far a search of similar help requests for this error range from missing parameters, missing pipes, use of single or multi-lines, and also concatenation issues but none of the answers seem to give a definitive reason. So I assume the issue is code format (which makes it a lot harder to track down).</p>
  <p>This is my script which I am writing to rename active directory users per target OU from whatever format they are now into a firstname.surname format.</p>
  <p>I have created a test OU in AD with some users who will trigger errors and some that will not. However, the users that should not give me an error are giving me the &quot;a positional parameter cannot be found that accepts argument &quot;firstname.surname&quot;</p>
  <p>I cannot see what is wrong with the script but hopefully, someone can give me some pointers.</p>
  <pre><code>Import-Module ActiveDirectory
  
  $users = $null
  
  $users = Get-ADUser -SearchBase &quot;ou=Testing,ou=Users,dc=my,dc=domain&quot; -Filter * -Properties *
  foreach ($user in $users) {
      Write-Host &quot;Processing... $($user)&quot;
      $newname = $null
  
      # Check first/last name is set
      if (!$user.givenName -or !$user.Surname) {
          Write-Host &quot;$($user) does not have first name or last name set. Please correct, skipping user.&quot;
          continue
      } else {
          $newname = (&quot;$($user.givenName).$($user.Surname)&quot;)
  
          #Check if new username already exists
          if (dsquery user -samid $newname) {
              Write-Host &quot;$($user) requires altered username with initial.&quot;
  
              if (!$user.Initials) {
                  Write-Host &quot;$($user) does not have any initials set. Please correct, skipping user.&quot;
                  continue
              }
  
              $newname = (&quot;$($user.givenName)$($user.Initials).$($user.Surname)&quot;)
  
              #Check if altered new username already exists
              if (dsquery user -samid $newname) {
                  Write-Host &quot;$($user) requires manual change. Please correct, skipping user.&quot;
                  continue
              }
          }
  
          try {
              #Change UPN
              Set-ADUser $user -userPrincipalName = $newname
              #Change DN
              Rename-ADObject -identity $user -Newname $newname
          } catch {
              Write-Host &quot;Error when renaming $($user). Error is: $($_.Exception.Message). User requires manual change. Please correct, skipping user.&quot;
              continue
          }
      }
  }
  </code></pre>