Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $CreateNewUser = $false;
- function anotherUser () {
- Write-Host "Do you want to create another User:"
- $Answer = Read-Host "Type Y for yes or N for No"
- if ($Answer -eq "Y" -or $Answer -eq "Yes") {
- createUserAndFolder
- } else {
- Write-Host "Good-Bye"
- }
- }
- function createUserAndFolder () {
- $Counter = 0
- $CheckPassword = $false
- $FirstName = ""
- $LastName = ""
- $SecurePassword = ""
- function getInput () {
- $str = "What is first name?"
- if ($counter -eq 1) {
- $str = "What is last name?"
- } elseif ($counter -eq 2) {
- $str = "What is password"
- }
- return Read-Host $str
- }
- function getPassword () {
- return Read-Host
- }
- do
- {
- $Result = getInput
- if ($Counter -lt 2) {
- if ($Result -cmatch '^[A-Z]{1}[a-z]{2,32}$') {
- if ($Counter -eq 0) {
- $FirstName = $Result
- } elseif ($Counter -eq 1) {
- $LastName = $Result
- }
- $Counter++
- } else {
- if ($Counter -eq 0) {
- Write-Host "$Result is not a valid name " -ForegroundColor red
- Write-Host "Name must be between 3 and 33 characters and start with upper letter!" -ForegroundColor red
- Write-Host "For example: Pesho" -ForegroundColor yellow
- } elseif ($Counter -eq 1) {
- Write-Host "$Result is not a valid name " -ForegroundColor red
- Write-Host "Name must be between 3 and 33 characters and start with upper letter!" -ForegroundColor red
- Write-Host "For example: Dimitrov" -ForegroundColor yellow }
- }
- } else {
- if ($Result -cmatch '^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$') {
- $SecurePassword = $Result | ConvertTo-SecureString -AsPlainText -Force
- $Counter++
- } else {
- Write-Host $Result
- Write-Host "Is not a valid password" -ForegroundColor red
- Write-Host "Password must contains minimum 8 characters, at least 1 uppercase letter, 1 lowercase letter and 1 number!" -ForegroundColor red
- }
- }
- } until ($Counter -gt 2)
- $Name = "$($Firstname) $($LastName)"
- $SamName = "$($Firstname.ToLower()).$($LastName.ToLower())"
- New-ADUser -Name $Name -SamAccountName $SamName -AccountPassword $Password -Enabled $true
- New-Item -Path "C:\Shared" -Name $SamName -ItemType "directory"
- anotherUser
- }
- createUserAndFolder
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement