-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserData-GiveToAdmin.ps1
More file actions
26 lines (21 loc) · 1.01 KB
/
UserData-GiveToAdmin.ps1
File metadata and controls
26 lines (21 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Takes Ownership of every folder/file in \\path\userdata\
# Also gives full access permissions to every folder/file
$startingDir = "\\path\drive$\userdata"
$Right="FullControl"
## Takes ownership of file to user running script, otherwise unable to set proper ownership later
takeown /f $startingDir /R /D Y
foreach($user in $(Get-ChildItem $startingDir)){
$userID = $user.Name.Split('.')[0]
$Principal="domain\user" # replace with whichever Admin user is running this
$rule=New-Object System.Security.AccessControl.FileSystemAccessRule($Principal, $Right, "Allow")
$acl2 = Get-Acl $user.FullName
$acl2.SetOwner([System.Security.Principal.NTAccount] $Principal)
$acl2.SetAccessRule($rule)
Set-Acl $user.FullName $acl2
foreach ($file in $(Get-ChildItem "$startingDir\$user" -Recurse)){
$acl = Get-Acl $file.FullName
$acl.SetOwner([System.Security.Principal.NTAccount] $Principal)
$acl.SetAccessRule($rule)
Set-Acl $file.FullName $acl
}
}