Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .Description
- Script used to create a new Domain User in Active Directory.
- #>
- #Grab some dynamic variables
- $firstName = Read-Host "First Name"
- $lastName = Read-Host "Last Name"
- $title = Read-Host "Title"
- $Dept = Read-Host "Department"
- $Password = Read-Host -AsSecureString "Password"
- $Office = Read-Host "Office"
- $Manager = Read-Host "Manager"
- #Set some Static variables
- $homepath = "\\File\Share\"
- $domain = '@' + (Get-ADDomain).dnsroot
- $lowerLN = $lastname.ToLower()
- $lowerFI = $firstName.substring(0,1).ToLower()
- $logon = $lowerFI + $lowerLN
- #Set the Address Tab Info variables
- if ($Office -like 'Lex Corp') {
- $Street = "Insert Street Here"
- $City = "Metropolis"
- $State = "ZZ"
- $Zip = '55555'
- }
- if ($Office -like 'Wayne Ent') {
- $Street = "Insert Street Here"
- $City = "Gotham"
- $State = "ZZ"
- $Zip = '77777'
- }
- if ($Office -like 'Scranton') {
- $Street = "Insert Street Here"
- $City = "Smallville"
- $State = "ZZ"
- $Zip = '99999'
- }
- #Set a new variable to clean the script up
- $Attributes =@{
- Enabled = $True
- Name = "$firstName $lastName"
- GivenName = $firstName
- Surname = $lastName
- SamAccountName = $logon
- UserPrincipalName = "$logon$domain"
- DisplayName = "$firstName $lastName"
- Department = "$Dept"
- Title = $Title
- Office = $Office
- Company = "Insert Company Here"
- AccountPassword = $Password
- HomeDrive = "H:"
- HomeDirectory = "$homepath$logon"
- Path = 'OU=Users,OU=$Dept,OU=Yep,DC=Contoso,DC=Com'
- StreetAddress = $Street
- City = $City
- State = $State
- PostalCode = $Zip
- Country = "US"
- Manager = get-aduser -Filter 'Name -like "$Manager"' -Properties SamAccountName | Select-Object -ExpandProperty SamAccountName
- }
- #Creating our new Domain User
- $mkuser = new-aduser $Attributes
- #Make sure that the account has to change it's password after the first logon
- $ChgPass = set-aduser -identity $logon -ChangePasswordAtLogon $True
- #This is where my adding to groups would go.....IF I HAD THEM!
- #Check to see if account exists
- #$complete = get-aduser -identity $logon
- #Look for the account in question, and if missing create it.
- If (!(Get-ADUser -Identity $logon))
- {
- & $mkuser
- & $ChgPass
- }
- else
- {
- Write-Host "The username already exists."
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement