Solved

New-ADUser Powershell

Posted on 2014-01-02
3
5,160 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

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

896 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

15 Experts available now in Live!

Get 1:1 Help Now