Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

New-ADUser Powershell

Posted on 2014-01-02
3
Medium Priority
?
6,064 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
Krzysztof Pytko earned 1200 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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Uncontrolled local administrators groups within any organization pose a huge security risk. Because these groups are locally managed it becomes difficult to audit and maintain them.
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
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 configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
Suggested Courses

596 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