Dec 18 2021 05:24 AM - edited Dec 21 2021 07:33 AM
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
1..500
#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! https://github.com/tomwechsler
Dec 19 2021 07:30 AM
Dec 19 2021 09:28 PM
Dec 19 2021 09:54 PM