Enabling Multiple Consumer Accounts via PowerShell in Active Directory

Enabling Multiple Consumer Accounts via PowerShell in Active Directory





PowerShell is a good scripting device — it not only will help preserve you time, it also delivers higher flexibility for executing repeated responsibilities. Almost all Windows roles and functions ship with PowerShell cmdlets.

You can use Windows Working Process cmdlets to perform operational responsibilities this kind of as examining the standing of a specific Windows service on many computers, examining the record of program put in on Windows computers, and so on.

And when it will come to interacting with Active Directory, most Active Directory admins also use PowerShell scripting. There are numerous PowerShell cmdlets delivered with Active Directory.Windows Server Tutorials

In Modern Server Tutorial, we will demonstrate how to use PowerShell to help bulk user accounts in Active Directory. Observe: You will be essential to set up Active Directory PowerShell modules on a supported Windows Working Process prior to you can use any of the PowerShell command examples delivered in this Server Tutorial.

Enabling Multiple Consumer Accounts

By default, when you produce a user account in Active Directory, the user account is enabled. Having said that, you may well locate on your own in a circumstance in which you need to help formerly disabled user accounts.

While you can use Active Directory Consumers and Computer systems to help user accounts independently, it may possibly get a considerable total of time when a substantial quantity of accounts is concerned. This is in which the Enable-ADAccount PowerShell cmdlet will come handy.

While it is effortless to help a one Active Directory user account from the Active Directory Consumers and Computer systems snap-in, the instance down below displays how you can help many Advert user accounts employing PowerShell. Let’s say you would like to help user accounts residing in a specific organizational unit. You will need to execute the pursuing PowerShell command to do this:

Get-ADUser -Filter "Title -like "*"" -SearchBase "OU=ProdOU1, OU=TestUsers, DC=ServerWatch, DC=Com" | Enable-ADAccount

The earlier mentioned command uses the Get-ADUser PowerShell cmdlet to accumulate all the buyers residing in the “OU=ProdOU1, OU=TestUsers, DC=ServerWatch, DC=Com” organizational unit, and then the Enable-ADAccount PowerShell cmdlet runs in opposition to every single retrieved user account from the organizational unit.

While the earlier mentioned command targets a precise organizational unit, the command down below can be made use of if you have the user account names stored in a text file:

$UserFile = "C:TempUserfile.CSV"

Get rid of-merchandise $UserFile -ErrorAction SilentlyContinue
$ReportFile = "C:TempUserStatus.CSV"

$ThisSTR = "Consumer Title, Account Status"
Include-Articles $ReportFile $ThisSTR

Foreach ($UserName in Get-Articles "$UserFile")

$Error.Very clear()
Enable-ADAccount -Identification "$UserName"
IF ($Error.Depend -ne )

$ThisSTR = $UserName+", Was enabled efficiently."
Include-Articles $ReportFile $ThisSTR

else

$ThisSTR = $UserName+", Error enabling Consumer account"
Include-Articles $ReportFile $ThisSTR



Generate-Host "PowerShell Script to help user accounts fully efficiently and report saved in $ReportFile"

After the earlier mentioned script has completed executing, a report file will be generated in the C:Temp directory with the name UserStatus.CSV, which includes the user name as nicely as irrespective of whether or not the Enable-ADAccount was executed efficiently for the concentrate on user. The report will also incorporate any mistake messages thrown by the Enable-ADAccount PowerShell cmdlet.

Observe:The UserFile.CSV file that includes the record of user accounts can be in two formats — possibly in SamAccountAccount or “DistinguishedName.” It is also worthy of mentioning that some of the user accounts mentioned in the UserFile.CSV file may possibly not exist in the Active Directory.

When Enable-ADAccount runs as part of the script, it will plainly detail why it couldn’t perform the operation efficiently in the circumstance of an issue. As outlined earlier mentioned, the motive could be that a specified user account does not exist in the Active Directory.

Conclusion

You can use the Enable-ADAccount PowerShell cmdlet to batch help user accounts in Active Directory. Modern server tutorial has thorough how you can concentrate on a precise organizational unit and has also illustrated how to help user accounts from a CSV file that includes the user account names. In our following Server tutorial, we will demonstrate how to disable bulk user accounts employing PowerShell.


Nirmal Sharma is a MCSEx3, MCITP and Microsoft MVP in Directory Providers. He specializes in directory expert services, Microsoft Azure, Failover clusters, Hyper-V, Process Middle and Trade Servers, and has been concerned with Microsoft systems due to the fact 1994. In his spare time, he likes to enable others and share some of his awareness by writing suggestions and content on a variety of internet sites and contributing to Health Packs for ADHealthProf.ITDynamicPacks.Net methods. Nirmal can be arrived at at [email protected].

Follow ServerWatch on Twitter and on Facebook






Server Install

Proxy Server

Server Install

Leave a Reply

Your email address will not be published.