Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import-Csv .\accounts.csv | foreach-object{
- $firstName = $_.name.split(" ")[0]
- $lastName = $_.name.split(" ")[1]
- $firstName + " " + $lastName
- $samAccountName = $firstName.Substring(0,1).ToLower() + $lastName.ToLower()
- $samAccountName
- $userPrinicpalName = $samAccountName + "@ticats.local";
- $userPrinicpalName
- $homeDirectory = "\\192.168.15.13\" + $samAccountName
- $homeDirectory
- $remotepath = "\\ticatsfs\f$\Users\" + $samAccountName
- "Remote path: " + $remotepath
- $domainusername = "ticats\" + $samAccountName
- "Domain username: " + $domainusername
- $proxyAddresses = "SMTP: " + $samAccountName + "@ticats.ca"
- "proxyAddresses: " + $proxyAddresses
- " "
- $User = Get-ADUser -Filter {samaccountname -eq $samaccountname}
- if ($User -eq $null)
- {
- $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
- $usercreate
- " "
- "---"
- " "
- Read-Host -Prompt "Press Enter to create AD user"
- 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
- Set-ADUser $samaccountname -replace @{proxyAddresses=$proxyAddresses}
- Add-ADGroupMember -Identity "Email Setup Users" -Member $samAccountName
- " "
- Read-Host -Prompt "User created. Press enter to move on to the next user"
- " "
- }
- if (!(Test-Path $remotepath))
- {
- "New-Item -Path " + $remotepath + " -type directory -Force"
- Read-Host -Prompt "Press Enter to create folders"
- New-Item -Path $remotepath -type directory -Force
- $colRights = [System.Security.AccessControl.FileSystemRights]"FullControl"
- $InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::None
- $PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
- $objType =[System.Security.AccessControl.AccessControlType]::Allow
- $objUser = New-Object System.Security.Principal.NTAccount("ticats.local",$samAccountName)
- $objACE = New-Object System.Security.AccessControl.FileSystemAccessRule ($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objType)
- $objACL = Get-ACL $remotepath
- $objACL.AddAccessRule($objACE)
- "Set-ACL " + $remotepath + " username: " + $objUser
- " "
- Read-Host -Prompt "Press Enter to add permissions"
- " "
- Set-ACL $remotepath $objACL
- " "
- Read-Host -Prompt "Press enter to move on to the next user"
- " "
- }
- }
- Read-Host -Prompt "---------------Press Enter to exit-----------------"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement