Powershell script update
Posted on 2016-11-07
I had to udate the script below and include the samaccount name which will be as follow :
And also include each created account in the folowing group :
"G_ID_NetworkTeam" which i don't know how to update in the below script.
Can you Help ?
Below is the Ps script.
$MYPASSWORD = Read-Host "Enter Password" -AsSecureString
[int] $counter = 8000
$USERNAME = "TCA000"+ $counter.tostring()
$USERPRINCIPALNAME = $USERNAME + "@it.us.sys"
$SAMACCOUNTNAME = $USERNAME + "@it.us.sys"
$DISPLAYNAME = "Network Engineer"
$FIRSTNAME = "Network Team"
$LASTNAME = "P2V"
$OUPATH = "OU=Network,OU=OU_Engineer,DC=it,DC=us,DC=sys"
$EMAILADDRESS = "firstname.lastname@example.org"
New-ADUser -Name $USERNAME -UserPrincipalName $USERPRINCIPALNAME -sAMAccountName $SAMACCOUNTNAME -DisplayName $DISPLAYNAME -GivenName $FIRSTNAME -Surname $LASTNAME -Path $OUPATH -Email $EMAILADDRESS -AccountPassword $MYPASSWORD -PasswordNeverExpires $True -Enabled $False
#LOG OF CREATED USERS
Get-ADUser -Identity $USERNAME -Properties EmailAddress,DisplayName,PasswordNeverExpires,Enabled | Select-Object Name,GivenName,Surname,DisplayName,EmailAddress,DistinguishedName,SamAccountName,UserPrincipalName,PasswordNeverExpires,Enabled | Out-file "NewUserResults.txt" -Append
} while ($counter -le 9999)