Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. import-Csv .\accounts.csv | foreach-object{
  4. $firstName = $_.name.split(" ")[0]
  5. $lastName = $_.name.split(" ")[1]
  6.  
  7. $firstName + " " + $lastName
  8.  
  9. $samAccountName = $firstName.Substring(0,1).ToLower() + $lastName.ToLower()
  10. $samAccountName
  11.  
  12. $userPrinicpalName = $samAccountName + "@ticats.local";
  13. $userPrinicpalName
  14.  
  15. $homeDirectory = "\\192.168.15.13\" + $samAccountName
  16. $homeDirectory
  17.  
  18. $remotepath = "\\ticatsfs\f$\Users\" + $samAccountName
  19. "Remote path: " + $remotepath
  20.  
  21. $domainusername = "ticats\" + $samAccountName
  22. "Domain username: " + $domainusername
  23.  
  24. $proxyAddresses = "SMTP: " + $samAccountName + "@ticats.ca"
  25. "proxyAddresses: " + $proxyAddresses
  26.  
  27. " "
  28.  
  29. $User = Get-ADUser -Filter {samaccountname -eq $samaccountname}
  30. if ($User -eq $null)
  31.     {
  32.     $usercreate = "New-ADUser -SamAccountName " + $samAccountName +" -UserPrincipalName " + $userPrinicpalName + " -Name " + $_.name + " -DisplayName " + $_.name + " -GivenName " + $firstName + " -SurName " + $lastName + " -Path " + '"' + $_.path + '"' + " -AccountPassword (ConvertTo-SecureString " + $_.password + " -AsPlainText -force) -Enabled $True -PasswordNeverExpires $True -PassThru -homedrive ""H"" -homedirectory " + $homeDirectory
  33.     $usercreate
  34.     " "
  35.     "---"
  36.     " "
  37.     Read-Host -Prompt "Press Enter to create AD user"
  38.  
  39.     New-ADUser -SamAccountName $samAccountName -UserPrincipalName $userPrinicpalName -Name $_.name -DisplayName $_.name -GivenName $firstName -SurName $lastName -Path $_.path -AccountPassword (ConvertTo-SecureString $_.password -AsPlainText -force) -Enabled $True -PasswordNeverExpires $True -PassThru -homedrive "H" -homedirectory $homeDirectory
  40.  
  41.     Set-ADUser $samaccountname -replace @{proxyAddresses=$proxyAddresses}
  42.    
  43.     Add-ADGroupMember -Identity "Email Setup Users" -Member $samAccountName
  44.  
  45.  
  46.     " "
  47.     Read-Host -Prompt "User created. Press enter to move on to the next user"
  48.     " "
  49.  
  50.     }
  51.  
  52. if (!(Test-Path $remotepath))
  53.     {
  54.    
  55.     "New-Item -Path " + $remotepath + " -type directory -Force"
  56.  
  57.     Read-Host -Prompt "Press Enter to create folders"
  58.  
  59.     New-Item -Path $remotepath -type directory -Force
  60.  
  61.     $colRights = [System.Security.AccessControl.FileSystemRights]"FullControl"
  62.  
  63.     $InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::None  
  64.     $PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
  65.  
  66.     $objType =[System.Security.AccessControl.AccessControlType]::Allow
  67.  
  68.     $objUser = New-Object System.Security.Principal.NTAccount("ticats.local",$samAccountName)
  69.  
  70.     $objACE = New-Object System.Security.AccessControl.FileSystemAccessRule ($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objType)
  71.  
  72.     $objACL = Get-ACL $remotepath
  73.  
  74.     $objACL.AddAccessRule($objACE)
  75.  
  76.     "Set-ACL " + $remotepath + "  username: " + $objUser
  77.     " "
  78.     Read-Host -Prompt "Press Enter to add permissions"
  79.     " "
  80.     Set-ACL $remotepath $objACL
  81.  
  82.     " "
  83.     Read-Host -Prompt "Press enter to move on to the next user"
  84.     " "
  85.     }
  86.  
  87. }
  88.  
  89.  
  90. Read-Host -Prompt "---------------Press Enter to exit-----------------"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement