Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/Why does the a positional parameter cannot be found that accepts argument error occur?
Next
Answered
Octavia Garcia
  • 32
Octavia Garcia
Asked: May 17, 20222022-05-17T13:48:54+00:00 2022-05-17T13:48:54+00:00In: Programs

Why does the a positional parameter cannot be found that accepts argument error occur?

  • 32

. Advertisement .

..3..

. Advertisement .

..4..

I am trying to write a programs that returns an invalid answer. I don’t know where the incorrect command is in the “a positional parameter cannot be found that accepts argument”. My detail is:

Import-Module ActiveDirectory
 
 $users = $null
 
 $users = Get-ADUser -SearchBase "ou=Testing,ou=Users,dc=my,dc=domain" -Filter * -Properties *
 foreach ($user in $users) {
  Write-Host "Processing... $($user)"
  $newname = $null
 
  # Check first/last name is set
  if (!$user.givenName -or !$user.Surname) {
  Write-Host "$($user) does not have first name or last name set. Please correct, skipping user."
  continue
  } else {
  $newname = ("$($user.givenName).$($user.Surname)")
 
  #Check if new username already exists
  if (dsquery user -samid $newname) {
  Write-Host "$($user) requires altered username with initial."
 
  if (!$user.Initials) {
  Write-Host "$($user) does not have any initials set. Please correct, skipping user."
  continue
  }
 
  $newname = ("$($user.givenName)$($user.Initials).$($user.Surname)")
 
  #Check if altered new username already exists
  if (dsquery user -samid $newname) {
  Write-Host "$($user) requires manual change. Please correct, skipping user."
  continue
  }
  }
 
  try {
  #Change UPN
  Set-ADUser $user -userPrincipalName = $newname
  #Change DN
  Rename-ADObject -identity $user -Newname $newname
  } catch {
  Write-Host "Error when renaming $($user). Error is: $($_.Exception.Message). User requires manual change. Please correct, skipping user."
  continue
  }
  }
 }

And I end up with the warning message:

a positional parameter cannot be found that accepts argument "firstname.surname"

Pls, suggest the best answer to fix it.

cannot be found that accepts argument
  • 2 2 Answers
  • 263 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    lyytutoria Expert
    2022-06-05T00:43:41+00:00Added an answer on June 5, 2022 at 12:43 am

    The cause:

    Cmdlets in powershell accept a bunch of arguments. When these arguments are defined you can define a position for each of them. This allows you to call a cmdlet without specifying the parameter name. So for the following cmdlet the path attribute is define with a position of 0 allowing you to skip typing -Path when invoking it and as such both the following will work.

    Get-Item -Path C:\temp\thing.txt
    Get-Item C:\temp\thing.txt

    However if you specify more arguments than there are positional parameters defined, you will get the following error.

    Get-Item C:\temp\thing.txt "*"

    Because this cmdlet does not know the way to accept the second positional parameter and you get the error. This can be fixed by telling it what the parameter is meant to be.

    Get-Item C:\temp\thing.txt -Filter "*"

    You are getting the error on the following line of code because it seems to be the only place you don’t specify the parameter names correctly.

    Set-ADUser $user -userPrincipalName = $newname

    Solution:

    Maybe it is treating the = as a parameter and $username as another parameter, so let’s try to specify the parameter name for $user and removing the =.

    • 9
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Léna Bertrand
    2022-05-25T20:01:33+00:00Added an answer on May 25, 2022 at 8:01 pm

    This problem occurred after I converted my Write-Host cmdlets into Write-Information. I had missed quotes and parens around parameters. Evidently, the signatures of cmdlets are not identical.

    Write-Host this is a good idea $here Write-Information this is a good idea $here <=BAD

    After spending 20-30 minutes looking through the function stack, this cmdlet signature was corrected.

    Write-Information ("this is a good idea $here") <=GOOD

    • 13
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.