Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $numUsers = "25"
- $FormatLength = "1"
- $userName = "LoginVSI"
- $passWord = "Password!"
- $userDomain = "sph.lan"
- $baseOU = "DC=sph,DC=lan"
- for ($i=11; $i -le $numUsers; $i++)
- {$fn = "{0:D$FormatLength}" -f $i
- $finalUser = $userName + $fn
- New-ADUser -name "$finalUser" -SamAccountName "$finalUser" -UserPrincipalName "$finalUser@$userDomain" -GivenName "$finalUser" -Surname "$finalUser" -DisplayName "$finalUser" -path "OU=Target,OU=Users,OU=LoginVSI,$baseOU" -AccountPassword (ConvertTo-SecureString -AsPlainText "$passWord" -Force) -ChangePasswordAtLogon $false -PasswordNeverExpires $true -ScriptPath "V4-VSI_Logon.cmd" -HomePage "http://www.loginvsi.com" -Enabled $true
- Add-ADGroupMember -Identity "CN=LoginVSI,OU=LoginVSI,$baseOU" -Members $finalUser
- homefolder($finalUser)
- profilefolder($finalUser)
- }
- function homefolder($Finaluser) {
- #**** home folder settings ****
- write-host $finaluser
- $username = "SPH\"+$finaluser
- $homeDIR = "E:\data\homefolders\"+ $finaluser
- $homeshare = "\\dc\home$\"+ $finaluser
- #when folder doesn't exist, create it for the user
- if(!(Test-Path -Path $homedir )){
- New-Item -ItemType directory -Path $homedir
- write-host "folder $homedir not found!"
- }
- Set-ADUser -identity $finaluser -HomeDirectory "$Homeshare" -HomeDrive "H:"
- $ACL = Get-Acl "$Homedir"
- $ACL.SetAccessRuleProtection($true, $false)
- $ACL.Access | ForEach { [Void]$ACL.RemoveAccessRule($_) }
- $ACL.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule("$NTDomain\Domain Admins","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")))
- $ACL.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule("$username","Modify", "ContainerInherit, ObjectInherit", "None", "Allow")))
- Set-Acl "$Homedir" $ACL
- }
- function profilefolder($finalUser) {
- #**** userprofile settings ****
- $profDIR = "E:\data\profiles\"+$finaluser
- $profshare = "\\dc\profiles$\"+$finaluser
- #when folder doesn't exist, create it for the user
- if(!(Test-Path -Path "$profdir.v2" )){
- New-Item -ItemType directory -Path "$profdir.v2"
- write-host "folder $profdir.v2 not found!"
- }
- #set profile properties
- set-aduser $finaluser -ProfilePath $profshare
- $username = "SPH\"+$finaluser
- $ACL = Get-Acl "$profdir.v2"
- $ACL.SetAccessRuleProtection($true, $false)
- $ACL.Access | ForEach { [Void]$ACL.RemoveAccessRule($_) }
- $ACL.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule("SPH\Domain Admins","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")))
- $ACL.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule("SYSTEM","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")))
- $ACL.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule("$username","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")))
- Set-Acl "$profDIR.v2" $ACL
- }
Advertisement
Add Comment
Please, Sign In to add comment