Write-Host ""
Write-Host ""
$startingDir = "\\fileserver\redirect"
$domain = "ExampleDomain.com"
cd $startingDir
$adminServiceAccount = New-Object System.Security.Principal.NTAccount($domain + "\" + "AdministratorAccountName")
Function setPermissions
{
param ($file, $user)
$user = $domain + "\" + $user
Write-Host user is $user
$objUser = New-Object System.Security.Principal.NTAccount($user)
Get-ChildItem $file -Recurse | ForEach-Object {
setOwner $_.FullName.ToString() $adminServiceAccount
}
#$acl.SetAccessRuleProtection($False,$True)
$acl = Get-Acl $file.ToString()
Write-Host $file
Add-NTFSAccess -Path $file -Account $user -AccessRights FullControl
Get-Acl $file |fl
Get-ChildItem $file -Recurse | ForEach-Object {
setOwner $_.FullName.ToString() $objUser
}
}
Function setOwner
{
param ($file, $user)
Write-Host Setting ownership of $file to $user
$owner = New-Object System.Security.Principal.NTAccount($user)
$acl = Get-Acl $file
$acl.SetOwner($owner)
Set-Acl $file $acl
}
Get-ChildItem $startingDir | ForEach-Object {
$folderFullPath = $_.FullName
$user = $_.Name.ToString()
Write-Host Setting permissions on $folderFullPath
setPermissions $folderFullPath $user
}
Wednesday, April 8, 2015
Fix NTFS permissions on user subfolders of a redirect folder
Ran in to this problem a few times and had to fix, script requires installation of NTFSSecurity. I made a script once that doesn't require NTFSSecurity, but it is much more complex.
Labels:
Systems
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment