Reputation: 35
New-ADUser -SamAccountName $user.SamAccountName -Name ($user.FirstName + " " + $user.LastName) `
-DisplayName ($user.FirstName + " " + $user.LastName) -GivenName $user.FirstName -Surname $user.LastName `
-EmailAddress ($user.FirstName + "_" + $user.LastName + $dnsroot) -UserPrincipalName ($user.SamAccountName + $dnsroot) `
-Title $user.title -manager $user.manager `
-Enabled $true -ChangePasswordAtLogon $false -PasswordNeverExpires $true `
-AccountPassword $defpassword -PassThru `
-AccountExpirationDate $expires -Path 'rop.com/ts/otos/ate/PMO/'`
-telephoneNumber "9856"'
-LoginScript "es.cmd"'
-Description "etant"'
-Street "unt"`
I don't work with PowerShell much so I am unsure how to fix this error.
The error I get is: Missing expression after unary operator '-'
Upvotes: 0
Views: 600
Reputation: 4089
There are a few issues.
As mentioned, you need to have a space between your backticks and the end of a line for line continuation. Also, on some of your last lines, you use single quotes (') instead of backticks (`).
If your last line in the sample code is the last line of your command, having a backtick at the end of it will cause errors.
Additionally, -telephoneNumber
is not a parameter of New-ADUser. The only default parameters that deal with phone numbers are -HomePhone
, -OfficePhone
, and -MobilePhone
. Otherwise, you need to use the -OtherAttributes
parameter.
In this case I think you want -OtherAttributes @{telephonenumber="9856"}
Upvotes: 1
Reputation:
I'm pretty sure you need a space before the backtick.
New-ADUser -SamAccountName $user.SamAccountName -Name ($user.FirstName + " " + $user.LastName) `
-DisplayName ($user.FirstName + " " + $user.LastName) -GivenName $user.FirstName -Surname $user.LastName `
-EmailAddress ($user.FirstName + "_" + $user.LastName + $dnsroot) -UserPrincipalName ($user.SamAccountName + $dnsroot) `
-Title $user.title -manager $user.manager `
-Enabled $true -ChangePasswordAtLogon $false -PasswordNeverExpires $true `
-AccountPassword $defpassword -PassThru `
-AccountExpirationDate $expires -Path 'rop.com/ts/otos/ate/PMO/' `
-telephoneNumber "9856" `
-LoginScript "es.cmd" `
-Description "etant" `
-Street "unt"
Upvotes: 1