Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # *** THIS SCRIPT IS PROVIDED WITHOUT WARRANTY, USE AT YOUR OWN RISK ***
- <#
- .DESCRIPTION
- Creates Active Directory Users in Bulk using a CSV file. Requires a typed password
- and a confirmation that matches to execute.
- .NOTES
- File Name: New-ADUser.ps1
- Author: David Hall
- Contact Info:
- Website: www.signalwarrant.com
- Twitter: @signalwarrant
- Facebook: facebook.com/signalwarrant/
- Google +: plus.google.com/113307879414407675617
- YouTube Subscribe link: https://www.youtube.com/c/SignalWarrant1?sub_confirmation=1
- Requires: Appropriate AD permissions
- Tested: PowerShell Version 5, Windows 10 and Windows Server 2012 R2
- .PARAMETER
- None
- .EXAMPLE
- Run it from the ISE or console
- #>
- ###############################################################
- #
- # Confirm-Password function
- #
- ###############################################################
- Function confirm-Password{
- $match = $false
- while($match -eq $false) {
- $PWD1 = Read-Host "ENTER PASSWORD"
- $PWD2 = Read-Host "CONFIRM PASSWORD"
- if($PWD1 -ne $PWD2) {
- Write-Warning "Passwords Do Not Match - Please Try Again ..."
- break
- }
- if($PWD1 -eq "" -or $PWD2 -eq "") {
- Write-Warning "Password Cannot be BLANK - Please Try Again ..."
- break
- }
- return $PWD1
- }
- }
- ###############################################################
- #
- # End Confirm-Password function
- #
- ###############################################################
- $import = 'c:\scripts\users.csv'
- $password = confirm-password
- if($password -ne "") {
- Import-CSV $import | ForEach {
- $user = New-ADUser `
- -SamAccountName ($_.FName+"."+$_.Lname) `
- -Name ($_.FName+" "+$_.LName) `
- -Displayname ($_.FName+" "+$_.LName) `
- -UserPrincipalName ($_.UserPrincipalName) `
- -Surname ($_.LName) `
- -GivenName ($_.Fname) `
- -Path ($_.ou) `
- -AccountPassword (ConvertTo-SecureString -AsPlainText $password -force )`
- -Enabled $true `
- -PasswordNeverExpires $false `
- -ChangePasswordAtLogon $true `
- -PassThru
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement