denzal2k4 Posted March 21, 2018 Posted March 21, 2018 So we are trying to create a folder structure with the users account name as the folder name and also give them and their line manager permissions on the folder, first part has been sorted I have a script that creates the folder it pulls the list of users from a txt file and assigns them full control the stumbling block is how I give their account manager access as well, I can get a CSV with the username and their account manager in the next row if that helps.... Current script: $Users = Get-Content "C:\data\names.txt" ForEach ($user in $users) { $newPath = Join-Path "C:\data\Users$" -childpath $user New-Item $newPath -type directory $acl = Get-Acl $newpath $permission = "DOMAIN\$user","FullControl","Allow" $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission $acl.SetAccessRule($accessRule) $acl | Set-Acl $newpath }
stevec_ Posted March 21, 2018 Posted March 21, 2018 Use a .csv and the Import-Csv cmdlet in powershell. You can use headings in your csv file then refer to them like so: $Users = Import-Csv -Path C:\users.csv ForEach ($User in $Users) { # You refer to the headings like so: $User.Heading New-Item -Path "C:\data\Users\$($User.Username)" #etc }
denzal2k4 Posted March 21, 2018 Author Posted March 21, 2018 So doing it that way, would I then just add in an additional $permission = "DOMAIN\($user.managers)","FullControl","Allow" Thanks
FishCustard Posted March 21, 2018 Posted March 21, 2018 [color=#333333]$permission = "DOMAIN\[b]$[/b]($user.managers)","FullControl","Allow"[/color] (the $ before the parentheses is important) Otherwise, yes. 1
stevec_ Posted March 21, 2018 Posted March 21, 2018 Exactly, something like: <# CSV format would be like: Username,LineManager username,linemanagersusername username,linemanagersusername username,linemanagersusername username,linemanagersusername etc.. #> $Users = Import-Csv -Path C:\users.csv ForEach ($User in $Users) { $newPath = Join-Path "C:\data\Users$" -childpath $User.Username New-Item $newPath -type directory $acl = Get-Acl $newpath $permission = "DOMAIN\$($User.Username)","FullControl","Allow" $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission $acl.SetAccessRule($accessRule) $permission = "DOMAIN\$($User.LineManager)","FullControl","Allow" $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission $acl.SetAccessRule($accessRule) $acl | Set-Acl $newpath } 1
denzal2k4 Posted March 21, 2018 Author Posted March 21, 2018 Amazing, thank you both that's sorted now!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now