Avatar of Dead_Eyes
Dead_Eyes
Flag for United Kingdom of Great Britain and Northern Ireland asked on

New-ADUser Powershell

Hi and Happy new year. I am doing a test run on my syntax before expanding my script but this error is driving me crazy. When I leave out the -path it works fine but when I try and Include a path it errors out and I cant figure out how it wants -path to be inputted. See below:
PS C:\Windows\system32> Import-Module -Name ActiveDirectory
New-ADUser `
-Name 12WWallis `
-CannotChangePassword 1 `
-ChangePasswordAtLogon 0 `
-Description Student `
-DisplayName "Will Wallis" `
-Enabled 1 `
-GivenName Will `
-HomeDirectory \\Server1\12WWallis$\Documents `
-HomeDrive N: `
-Initials WW `
-PasswordNeverExpires 1 `
-Path OU=YOE2012 `
-SamAccountName 12WWallis `
-Surname Wallis `
-UserPrincipalName 12WWallis@TestDomain.NET

New-ADUser : No superior reference has been configured for the directory service. The directory service is
therefore unable to issue referrals to objects outside
this forest
At line:2 char:1
+ New-ADUser `
+ ~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (CN=12WWallis,OU=YOE2012:String) [New-ADUser], ADException
    + FullyQualifiedErrorId : ActiveDirectoryServer:8406,Microsoft.ActiveDirectory.Management.Commands.NewADUser
 

PS C:\Windows\system32> Import-Module -Name ActiveDirectory
New-ADUser `
-Name 12WWallis `
-CannotChangePassword 1 `
-ChangePasswordAtLogon 0 `
-Description Student `
-DisplayName "Will Wallis" `
-Enabled 1 `
-GivenName Will `
-HomeDirectory \\Server1\12WWallis$\Documents `
-HomeDrive N: `
-Initials WW `
-PasswordNeverExpires 1 `
-Path ou=YOE2012,ou=Students,DC=TestDomain,DC=NET `
-SamAccountName 12WWallis `
-Surname Wallis `
-UserPrincipalName 12WWallis@TestDomain.NET

New-ADUser : Cannot convert 'System.Object[]' to the type 'System.String' required by
parameter 'Path'. Specified method is not supported.
At line:14 char:7
+ -Path ou=YOE2012,ou=Students,DC=TestDomain,DC=NET `
+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [New-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.ActiveDirectory.Management.Commands.NewADUser
PowershellActive Directory

Avatar of undefined
Last Comment
Dead_Eyes

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Krzysztof Pytko

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Dead_Eyes

ASKER
Never mind finally figured it needed '' marks around it so -path 'OU=YOE2012,OU=Students,DC=TestDomain,DC=NET'
Dead_Eyes

ASKER
I've requested that this question be closed as follows:

Accepted answer: 0 points for Dead_Eyes's comment #a39751036

for the following reason:

Figured it out myself in the end
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy