question

DeiBertine-5145 avatar image
0 Votes"
DeiBertine-5145 asked DeiBertine-5145 commented

Powershell error positional parameter cannot be found that accepts argument

Greetings,
I'm trying to create a simple ps script that will clear telephone number from a large user group in AD, pulling from a csv file however keep getting this error and not sure where or why it is failing...I'd appreciate the feedback or any assistance you could provide. Cheers.

$users = Import-Csv -Path C:\user.csv
foreach ($user in $users) {
Get-ADUser $user.SamAccountName -Properties * -SearchBase 'ou=Users,DC=cotm,DC=local' | Set-ADUser -Clear telephone
}

ERROR:

Get-ADUser : A positional parameter cannot be found that accepts argument 'fletterman'.
At C:\phone.ps1:5 char:1
+ Get-ADUser $user.SamAccountName -Properties -SearchBase 'ou=...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ADUser], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Get-ADUser : A positional parameter cannot be found that accepts argument 'gramone'.
At C:\phone.ps1:5 char:1
+ Get-ADUser $user.SamAccountName -Properties
-SearchBase 'ou=...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ADUser], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser

windows-server-powershellwindows-active-directory
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered DeiBertine-5145 commented

Hi,

You need to use the -filter parameter to specify an ADUser property and the attribute should be "telephonenumber", not "telephone"

 foreach ($user in $users) {
     $sam = $user.SamAccountName
     Get-ADUser -Filter {SamAccountName -eq $sam} -Properties * -SearchBase 'ou=Users,DC=cotm,DC=local' | Set-ADUser -Clear telephonenumber
 }

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you Ian Xue, that was very helpful on your post highlighting what needs to be corrected in the script. Keep up the good work! :-)

0 Votes 0 ·
RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

Because you used the -SearchBase parameter you cannot use the -Identity parameter. The -Identity parameter accepts a unique identifier -- there's no search for a match as there is with a -Filter or -LDAPFilter, so you can't specify where in the AD to look. The error is the result of there being three different parameter sets for the Get-ADUser cmdlet and you've used a parameter that excludes the use of the -Identity parameter.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.