0

I made this Line to add new users but the AD doesnt enable my account

New-ADUser (Read-Host "Enter Username") -AccountPassword (Read-Host -AsSecureString "Enter Password") | Enable-ADAccount

Why is that?

2 Answers 2

1

If you look at TechNet for New-ADUser cmdlet you can see the following buried in the parameter description for -passthru:

By default (i.e. if -PassThru is not specified), this cmdlet does not generate any output.

Which you can also see in practice.

PS C:\Users\matt> new-aduser "matt"

PS C:\Users\matt> 

You are essentially passing $null to Enable-ADAccount which is why nothing appears to be happening. You need to use the -PassThru switch, as stated above, then it should work.

PS C:\Users\matt> new-aduser "matt" -PassThru


DistinguishedName : CN=matt,CN=Users,DC=DOMAIN,DC=NET
Enabled           : False
GivenName         : 
Name              : matt
ObjectClass       : user
ObjectGUID        : 914fccdc-11ce-442e-b247-e4fd24f90023
SamAccountName    : matt
SID               : S-1-5-21-961215277-3068250917-3774519051-11002
Surname           : 
UserPrincipalName : 
Sign up to request clarification or add additional context in comments.

2 Comments

I think you have to use the PassThru switch. See technet.microsoft.com/en-us/library/ee617253.aspx. "Returns the new user object when the PassThru parameter is specified. By default, this cmdlet does not generate any output."
How can i set that new user must change his password at the next logon, at the same line command above
0

Try this instead

New-ADUser (Read-Host "Enter UserName") -AccountPassword (Read-Host -AsSecureString "Enter Password") -Enabled:$true

I've never piped a new user account anywhere, but you can enable the account in the same line.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.