Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###########################################################
- # AUTHOR : Ataur Rasool - IT Dept
- # DATE : 02-05-2016
- # COMMENT : This script creates new Active Directory user On PDC03
- # VERSION : 2
- ###########################################################
- #What do we need?
- #Domain DNS suffix
- #PDC02 AD details - v2
- #PDC03 AD details - v3
- #FirstName
- #LastName
- #Verification
- #Password
- #Loop
- #----------------------------------------------------------
- #
- # LOAD ASSEMBLIES AND MODULES
- #----------------------------------------------------------
- Import-Module ActiveDirectory -ErrorAction SilentlyContinue
- Write-Host "********************************************************************"
- Write-Host "** New User Creation Script **"
- Write-Host "********************************************************************"
- #Ask for the information required for the new UserAccount
- $FirstName = Read-Host "Enter users's First Name"
- $LastName = Read-Host "Enter user's Last Name"
- $UserName = Read-Host "Enter user ID (ie - arasool)"
- $Password = Read-Host "Enter user's Password - Symbols are allowed"
- Write-Host "Checking if user already exists - Please give this time."
- # Go to sleep - Allows time in between the script to be efficient, and parse no errors.
- Start-Sleep -s 5
- # Check - Does this user already exist?
- strUserName = $UserName
- dtStart = TimeValue(Now())
- Set objConnection = CreateObject("ADODB.Connection")
- objConnection.Open "Provider=ADsDSOObject;"
- Set objCommand = CreateObject("ADODB.Command")
- objCommand.ActiveConnection = objConnection
- objCommand.CommandText = _
- "PDC03;(&(objectCategory=User)" & _
- "(samAccountName=" & strUserName & "));samAccountName;subtree"
- Set objRecordSet = objCommand.Execute
- If objRecordset.RecordCount = 0 Then
- WScript.Echo "sAMAccountName: " & strUserName & " does not exist."
- Else
- WScript.Echo strUserName & " exists."
- End If
- objConnection.Close
- # Print the information on the screen, and confirm if the information is correct
- Write-Host "`nFirst Name:`t`t$FirstName" -ForegroundColor Yellow
- Write-Host "Last Name:`t`t$LastName" -ForegroundColor Yellow
- Write-Host "UserID: `t`t$UserName" -ForegroundColor Yellow
- Write-Host "Password: `t`t$Password" -ForegroundColor Yellow
- $Answer = Read-Host "Is this the information you want to use? (Y/N)"
- If ($Answer.ToUpper() -ne "Y")
- { Write-Host "`n`nOK. Restart the script...`n" -ForegroundColor RED
- break
- }
- #If answer is "n" - go back to the beginning.
- #Create the user account
- Set objOU = GetObject("LDAP://OU=management,dc=fabrikam,dc=com")
- Set objUser = objOU.Create("User", "cn=$UserName")
- objUser.Put "sAMAccountName", $UserName
- objUser.SetInfo
- #Password does not expire
- Set-ADUser -Identity $UserName -PasswordNeverExpires $true
- WScript.Echo "Password never expires is now enabled"
- Write-Host "The following username, " $UserName ",has been created." -ForegroundColor Green
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement