Solved

New-ADUser Powershell

Posted on 2014-01-02
3
5,076 Views
Last Modified: 2014-01-02
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
0
Comment
Question by:Dead_Eyes
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
Krzysztof Pytko earned 300 total points
ID: 39751031
Yes, this happens because you need to use distinguished name for OU. So, the second example given by you should work if you put it into quotas ""

So, let's try with that

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

Open in new window


Regards,
Krzysztof
0
 

Author Comment

by:Dead_Eyes
ID: 39751036
Never mind finally figured it needed '' marks around it so -path 'OU=YOE2012,OU=Students,DC=TestDomain,DC=NET'
0
 

Author Comment

by:Dead_Eyes
ID: 39751055
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
0

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
This article will help you understand what HashTables are and how to use them in PowerShell.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now