Enable User Accounts with PowerShell

Question: How to enable AD user account using Windows PowerShell cmdlets?

Answer (shamelessly stolen from Andrei’s post in the PowerGUI discussion forum):

1. [If this is a new account] Create the account using New-QADUser. Make sure the password is also set (-UserPassword parameter)

2. Enable the account by setting userAccountControl to 512: e.g.

Set-QADUser TEST\testuser -ObjectAttributes @{userAccountControl=512}

Bulk account provisioning: 

If you want to do that in bulk using csv file for bulk user account provisioning this might (depending on the columns in your file and attributes being set) look like:

PS C:\> Import-Csv users.csv | ForEach-Object {New-QADUser -ou acme.local/demo -name $_.Name -UserPassword $_.Password

PS C:\> Import-Csv users.csv | ForEach-Object {Set-QADUser $_.Name -ObjectAttributes @{userAccountControl=512}}

Due to AD cmdlets not having a community site of their own we have created a forum for Active Directory PowerShell discussions on PowerGUI.org. Andrei and other members of his team are there for your questions, feature requests, etc.

Tags: , , , ,

6 Responses to “Enable User Accounts with PowerShell”


  1. 1 Ms.Pat July 21, 2007 at 7:35 pm

    when i open the control panel & click on user accounts a blank page comes up. How do i get into user accounts??

  2. 2 dmitrysotnikov July 21, 2007 at 8:03 pm

    It looks like we are actually talking about different types of accounts. I am primarily writing about Active Directory management – so these are the accounts which administrators set up in enterprise networks.

    It looks like you are asking about local accounts on a Windows XP (or Vista) computer. While I am not a specialist at troubleshooting such issues one of the possible reasons might be your lack of administrative privileges on the computer. Try logging in as an administrator and see if you can now see all accounts (it might take a few seconds before the list gets populated.)

  3. 3 Ms.Pat July 22, 2007 at 6:10 pm

    Thank you but in order to login in as an administrator i have to get into the user account in the control panel which i cannot do. The screen comes up blank but on top it says “screen name server” & i don’t have a clue what that means.

  4. 4 dmitrysotnikov July 23, 2007 at 11:15 am

    I found a few posts on the internet mentioning the same problem but none seems to suggest a good workaround so you might have to roll-back to a previously saved system state or even reinstall Windows if none of these help (and you can’t use Microsoft’s tech support):

    http://windowsxp.mvps.org/useracc.htm

    http://forums.techguy.org/windows-nt-2000-xp/586157-user-accounts-folder-empty.html

  5. 5 Luke April 9, 2010 at 12:09 am

    Hi,

    I’m not sure if I’m the only one who would find this useful but here is the scenario. I work for a firm, I receive advance notice of new users starting on particular dates. Due to security and other reasons, I create the account and then disable them until the user has commenced and then enable the account manually. Is there a way to either Schedule the Enable Account? Something like an ‘Enable As of’. Is that possible with PowerShell? I am new to it and unsure of the capabilities.

    Thanks,
    Luke

    • 6 Dmitry Sotnikov April 9, 2010 at 11:08 am

      Luke,

      Sure. You just create a script with Enable-QADUser, and then create a scheduled task which would run: powershell.exe c:\myspript.ps1

      If you need further assistance – feel free to ask on the Forums at http://powergui.org.

      Dmitry


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




My Recent Tweets

Legal

The posts on this blog are provided “as is” with no warranties and confer no rights. The opinions expressed on this site are mine and mine alone, and do not necessarily represent those of my employer - WSO2 or anyone else for that matter. All trademarks acknowledged.

© 2007-2014 Dmitry Sotnikov

April 2007
M T W T F S S
« Mar   May »
 1
2345678
9101112131415
16171819202122
23242526272829
30  

%d bloggers like this: