An example why PowerShell is so important!



Dear Microsoft and PowerShell Friends,


Imagine the following scenario: Monday morning 08.00, you receive a call and are asked, are the 500 Active Directory test accounts created? Which test accounts?? Yes, the test accounts we need today and tomorrow. From 08.30 we need these accounts!


What comes now...panic...or calmness itself?


Let's do an experiment together.

I will create an account normally with the GUI (Active Directory Users and Computers) and measure the time.



Wow, OK! That was 53 seconds (not bad, right?) to create an Active Directory account. But now let's take a closer look. We were talking about 500 accounts. You don't have to be a math genius to realize that this is going to take a very long time. 500 accounts times one minute (53 seconds rounded to one minute) is 500 minutes. 500 minutes divided by 60 equals 8.333 hours (Lunch and to the toilet not included! ;-))!


That's where PowerShell comes in. I use the following for this (The hashtags are comments):

#We used a range operator


#Create 500 training (test) accounts
1..500 | ForEach-Object {New-ADUser -Name "User$_" -AccountPassword (ConvertTo-SecureString -AsPlainText "DemoPass1!" -Force) -Enabled:$TRUE}


#New-Aduser (Default cmdlet for creating a user)
#ConvertTo-SecureString (plain text is translated to a SecureString format)


Important: I know in this PowerShell Onliner is a password in plain text. This is absolutely not good, but these test accounts are used only two days and then deleted again. For this reason it is absolutely ok for this example. As a general rule, NO passwords in scripts.


But now back to our experiment. Now I will create the accounts with the PowerShell Onliner and measure the time as well. Let's rock n' roll!!



Super fast!! 500 accounts in less than 25 seconds! Really a great result. In the meantime it is 08.10 o'clock, what do we do now with the remaining 20 minutes (ha-ha-ha).


I hope this article has given you a good foundation why PowerShell is SO important. Thank you for taking the time to read this article.


Kind regards, Tom Wechsler


P.S. All scripts (#PowerShell, Azure CLI, #Terraform, #ARM) that I use can be found on github!

4 Replies
Yes, I totally agree, PowerShell is one of the great things Microsoft ever made, it solves the problem of bulk modification, and automation.
One great thing is how it can handle objects from multiple systems and pass them through a pipeline to another solution, such as and in your example, enabling the mailbox for each of these test users.

Great post.
Thank you!
Thank you :smiling_face_with_smiling_eyes:.

I have doubt.
What will be the user account names?
In this example, the accounts are named User01 - User500, since they are very simple test accounts. Regards, Tom