Ok, first off I self-taught Powershell. I thought, "It can't be too hard can it?" And it hasn't been but for some reason my script will not do what it is supposed to do:
Add-PSSnapin Quest.ActiveRoles.ADManagement Set-ExecutionPolicy RemoteSigned $fname = Read-Host 'What is their first name?' $lname = Read-Host 'What is their last name?' $uname = Read-Host 'What is their user name?' $mobile = Read-Host 'What is their cell number?' $office = Read-Host 'Which office are they working at?' $dname = $lname + ', ' + $fname $pass = Read-Host 'What is the users password?' -AsSecureString $role = Read-Host 'Which department is the user belonging to? (QAT, PA, CSR)' $permission = 'Would you like to create the user? (Y or N)' If ($role-eq 'QAT') { $template = 'QAT Template' $tempuser = 'qattemplate' If($permission-eq 'Y') { Get-QADUser $template -export New-QADUser -ParentContainer '[redacted]' -SamAccountName $uname -Name $dname -DisplayName $dname -FirstName $fname -LastName $lname -UserPassword $pass -department 'Services(QAT)' -office $office -description 'Services(QAT)' -mobilephone $mobile -import Set-QADUser "$lname $fname" -UserMustChangePassword $true Get-QADMemberOf [redacted]\$tempuser | ? {$_.Name -ne "Domain Users"} | Add-QADGroupMember -Member [redacted]\$uname } Else { Exit } } Elseif ($role-eq 'CSR') { $template = 'CSR Template' $tempuser = 'csrtemplate' If($permission-eq 'Y') { Get-QADUser $template -export New-QADUser -ParentContainer '[redacted]' -SamAccountName $uname -Name $dname -DisplayName $dname -FirstName $fname -LastName $lname -UserPassword $pass -department 'Services(QAT)' -office $office -description 'Services(QAT)' -mobilephone $mobile -import Set-QADUser "$lname $fname" -UserMustChangePassword $true Get-QADMemberOf [redacted]\$tempuser | ? {$_.Name -ne "Domain Users"} | Add-QADGroupMember -Member [redacted]\$uname } Else { Exit } } Elseif ($role-eq 'PA') { $template = 'PA Template' $tempuser = 'patemplate' If($permission-eq 'Y') { Get-QADUser $template -export New-QADUser -ParentContainer [redacted] -SamAccountName $uname -Name $dname -DisplayName $dname -FirstName $fname -LastName $lname -UserPassword $pass -department 'Services(QAT)' -office $office -description 'Services(QAT)' -mobilephone $mobile -import Set-QADUser "$lname $fname" -UserMustChangePassword $true Get-QADMemberOf [redacted]\$tempuser | ? {$_.Name -ne "Domain Users"} | Add-QADGroupMember -Member [redacted]\$uname } Else { Exit } } Else { Write-Host 'That input is not correct. Please try again.' Exit }
Now what I would like it to do is after you enter the department it goes through the motions in creating the user (and yes my coding is terrible... any suggestions please let me know!). Instead what it does is the script terminates after entering in the department and doesn't show anything. The only time it does is when you enter an incorrect response.
Anyone have any ideas?