tools/Fix-UserFolderPermissions.ps1
Function Grant-UserFolderPermissions { <# .SYNOPSIS This function will grant a user full access to their home and profile folders (from their AD Attribute) .NOTES Name: Grant-UserFolderPermissions Author: Elliott Marter .EXAMPLE Grant-UserFolderPermissions -Username john.wick .LINK https://www.powershellgallery.com/profiles/elliottmarter #> [cmdletbinding(SupportsShouldProcess=$True)] param( [Parameter( Mandatory = $true )] [string]$UserName ) $Domain = (Get-ADDomain).Name if ($Username) { try { $User = Get-ADUser -Filter {SamAccountName -eq $UserName} -Properties * $HomeFolder = $User.HomeDirectory $ProfileFolder = $User.ProfilePath $NTFS_Params = @{ Account = "$Domain\$UserName" AccessRights = "FullControl" AppliesTo = "ThisFolderSubfoldersAndFiles" } Write-Output "Fixing permissions for $HomeFolder" Add-NTFSAccess -Path $HomeFolder @NTFS_Params Write-Output "Fixing permissions for $ProfileFolder" Add-NTFSAccess -Path $ProfileFolder @NTFS_Params } Catch { Write-Error "$_.Exception.Message" } } } |