Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Import AD Silently
- Import-Module ActiveDirectory -ErrorAction SilentlyContinue
- #Grab dynamic Variables
- $givenname = Read-Host "Input given name"
- $surname = Read-Host "Input surname"
- $jobtitle = Read-Host "Input job title"
- $department = Read-Host "Input Department"
- $password = Read-Host -AsSecureString "Password"
- $Office = Read-Host "Input Office"
- $Manager = Read-Host "Manager"
- #set static variables
- $homepath = "\\shipleyfs2\users\"
- $domain = '@' + (Get-ADDomain).dnsroot
- $lowerLN = $surname.Tolower()
- $lowerFN = $givenname.Tolower()
- $logon = "$lowerFN.$lowerLN"
- $email = "@accentgroup.org"
- #Set the Address Tab Info variables
- if ($office -like 'Charlestown House') {
- $Street = "Acorn Park Industrial Estate"
- $City = "Charlestown"
- $state = "Shipley"
- $Zip = "BD17 7SW"
- }
- #Set new variables
- $Attributes =@{
- Enabled = $True
- Name = "$givenname $surname"
- Givenname = $givenname
- Surname = $surname
- SamAccountName = $logon
- UserPrincipalName = "$logon$domain"
- DisplayName = "$givenname $surname"
- Department = "$Department"
- Description = $jobtitle
- EmailAddress = "$lowerFN.$lowerLN$email"
- Title = $jobtitle
- Office = $Office
- Company = "Accent Corporate Services Limited"
- AccountPassword = $password
- HomeDrive = "H:"
- HomeDirectory = "$homepath$logon"
- StreetAddress = $Street
- City = $City
- State = $state
- PostalCode = $zip
- Country = "GB"
- 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