Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #INPUT PROMPTS
- $Firstname = Read-Host 'Firstname'
- $Lastname = Read-Host 'Lastname'
- $initials = Read-Host 'Initials (please use periods for example - J.A.)'
- $UserID = Read-Host 'UserID'
- $department = Read-Host 'Department'
- $title = Read-Host 'Title'
- $description = Read-Host 'Employee ID'
- $tstnr = Read-Host 'Office Phone'
- $CopyFromUser = Read-Host 'Copy rights from to (if not - push on enter)'
- $OUPath = Read-Host 'Intern or Extern'
- function New-DisplayName
- {
- <#
- CBH [Comment Based Help] goes here
- #>
- [CmdletBinding ()]
- Param
- (
- [Parameter (
- Mandatory,
- Position = 0
- )]
- [string]
- $FirstName,
- [Parameter (
- Mandatory,
- Position = 1
- )]
- [string]
- $LastName
- )
- begin {}
- process
- {
- $SplitLName = $LastName.Split(' ')
- $PartOne = $SplitLName[-1]
- $PartTwo = $FirstName[0]
- if ($SplitLName.Count -gt 1)
- {
- $PartThree = $SplitLName[0..($SplitLName.Count - 2)] -join ' '
- '{0}, {1}. {2} ({3})' -f $PartOne, $PartTwo, $PartThree, $FirstName
- }
- else
- {
- '{0}, {1}. ({2})' -f $PartOne, $PartTwo, $FirstName
- }
- }
- end {}
- } # end >> function New-DisplayName
- #USED FOR OUPATH
- $OUPathValidate = $true
- While ($OUPathValidate) {
- If ($OUPath.ToUpper() -eq 'Intern') {
- $OUPath = 'OU=Intern,OU=Users,OU=ZERO,DC=int,DC=rpz,DC=nl'
- $OUPathValidate = $false
- } ElseIf ($OUPath.ToUpper() -eq 'Extern') {
- $OUPath = 'OU=Extern,OU=Users,OU=ZERO,DC=int,DC=rpz,DC=nl'
- $OUPathValidate = $false
- } Else {
- Write-Host 'Unknown value - User Intern or Extern'
- }
- }
- # check if the user ID exists in AD
- if (Get-ADUser -Filter { SamAccountName -eq $UserID })
- {
- # if it exists, create a loop and get the first free name with a number behind, starting at 2
- $userNotFound = $true
- $count = 1
- while($userNotFound -eq $true)
- {
- $count++
- # create a temporary variable with the new name to check with
- $tempID = "$userid$count"
- if (-not (Get-ADUser -Filter { SamAccountName -eq $tempID }))
- {
- $userNotFound = $false
- }
- }
- # set the user ID to the new name
- $UserID = "$($UserID)$count"
- }
- #STATIC VARIABLES
- $Password = (ConvertTo-SecureString -AsPlainText 'ZERO' -Force)
- $company = 'ZERO'
- $Displayname = New-DisplayName -FirstName $FirstName -LastName $LastName
- $profilePath = "\\int.ZERO.nl\Users\Profiles\$UserID"
- $OfficePhone = $tstnr
- $aliasid = $UserID.Insert(1,'.')
- #USED TO ADD PARAMETERS
- $Parameters = @{
- 'SamAccountName' = $UserID
- 'UserPrincipalName' = $UserID
- 'Name' = "$Firstname $Lastname"
- 'GivenName' = $Firstname
- 'Surname' = $Lastname
- 'DisplayName' = $Displayname
- 'AccountPassword' = $password
- 'ChangePasswordAtLogon' = $true
- 'Enabled' = $true
- 'Path' = $OUPath
- 'company' = $company
- 'department' = $department
- 'description' = $description
- 'title' = $title
- 'profilePath' = $profilePath
- 'OfficePhone' = $OfficePhone
- 'initials' = $initials
- }
- "Username = $UserID"
- New-ADUser @Parameters
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement