Situatie
Now, let’s make our task a little bit harder and create ten similar Active Directory accounts in bulk, for example, for our company’s IT class, and set a default password (P@ssw0rd) for each of them. To send the default password in a protected state, we must use the ConvertTo-SecureString parameter. Here’s the script to use:
Solutie
$path=”OU=IT,DC=enterprise,DC=com” $username=”ITclassuser” $count=1..10 foreach ($i in $count) { New-AdUser -Name $username$i -Path $path -Enabled $True -ChangePasswordAtLogon $true ` -AccountPassword (ConvertTo-SecureString “P@ssw0rd” -AsPlainText -force) -passThru }
Now let’s make our script more flexible by adding the Read-Host parameter, which will ask for the name and number of users:
path="OU=IT,DC=enterprise,DC=com" $username=Read-Host "Enter name" $n=Read-Host "Enter Number" $count=1..$n foreach ($i in $count) { New-AdUser -Name $username$i -Path $path -Enabled $True -ChangePasswordAtLogon $true ` -AccountPassword (ConvertTo-SecureString "P@ssw0rd" -AsPlainText -force) -passThru }
Leave A Comment?