Skip to content

Commit

Permalink
derp
Browse files Browse the repository at this point in the history
  • Loading branch information
cosine83 committed Dec 9, 2021
1 parent bb62d90 commit 714449e
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions Change Home Directory Permissions (All Users).ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@ Import-Module NTFSSecurity

$ErrorActionPreference = "SilentlyContinue"

$query = Get-ADUser -Filter {Enabled -eq $true} | Sort SamAccountName
#$query = Get-ADGroupMember "Group"
$users = $query.SamAccountName
$query = Get-ChildItem "\\ttfiler02\rdrive\Inbox\Dom Cota" -Directory -Recurse
$Admin = "BUILTIN\Administrators"
$Dadmins = "DOMAIN\Domain Admins"
$Dadmins = "CORP\Domain Admins"
$Sys = "NT AUTHORITY\SYSTEM"
$SD = "CORP\Service_Desk"

foreach ($user in $users) {
$userH = Get-ADUser $user -Properties HomeDirectory
$HDrive = $userH.HomeDirectory
Set-NTFSOwner -Path $HDrive -Account $Admin
Disable-NTFSAccessInheritance -Path $HDrive -RemoveInheritedAccessRules
Get-NTFSAccess -Path $HDrive | Remove-NTFSAccess
Add-NTFSAccess -Path $HDrive -Account DOMAIN\$user, $Admin, $Dadmins, $Sys -AccessRights FullControl
Write-Host -Foreground Yellow -Background Black "Changed H drive permissions for $user"
foreach ($folder in $query) {
Set-NTFSOwner -Path $folder.FullName -Account $Admin
Disable-NTFSAccessInheritance -Path $folder.FullName -RemoveInheritedAccessRules
Get-NTFSAccess -Path $folder.FullName | Remove-NTFSAccess
Add-NTFSAccess -Path $folder.FullName -Account $Admin, $Dadmins, $Sys, $SD -AccessRights FullControl
Write-Output "Changed Inbox folder permissions on $($folder.FullName)"
}

0 comments on commit 714449e

Please sign in to comment.