Cyber Security

Grant Administrators Full Control Access on Roaming Profiles Folders (Grant-RoamingProfilesAccess)

Maybe you already had the following problem: You’re using roaming profiles. You are the administrator of the domain. You can’t access the roaming profiles folder. You have to take ownership of each folder and grant yourself access to every subfolder inside the parent folder. It’s a nuisance. That’s over now. Just use my advanced PowerShell function Grant-RoamingProfilesAccess to get access to all profiles folder and files.

The Roaming Profiles Folder

In my case, all roaming profiles are stored on my domain controller in c:\Profiles.

Unbenannt.PNG

When I try to access that folder, I get an Access Denied.

You don’t currently have permissions to access this folder.

Unbenannt.PNG

If you now think you can get access simply by following the instructions and clicking on Continue, then you are right. But what if you need access to all profiles? It is very tedious to do the work for all folders. That brought me to an idea: I will make function out of it to grant access to all profiles and profiles subfolders. Let’s jump in.

Breaking into the Profiles Folders

Firstly, we have to take ownership of all folders. Secondly, we have to grant full access to the administrators group. My function will do all that.

Here it is in action:


Grant-RoamingProfilesAccess -Path C:\Profiles\

1.PNG

After running that command, administrators have full access to all folders including sub folders.

The function Grant-RoamingProfilesAccess

Here is the code:


function Grant-RoamingProfilesAccess {

# .SYNOPSIS
# Grant-RoamingProfilesAccess is an advanced Powershell function. It takes ownership of the users roaming profiles folders and grants the administrators group full access.

# .DESCRIPTION
# Uses takeown and icacls. Define the path to the roaming profiles root directory.

# .PARAMETER
# Path
# Enter the path to the roaming profiles root folder.

# .EXAMPLE
# Grant-RoamingProfilesAccess -Path C:\Profiles\

# .NOTES
# Author: Patrick Gruenauer
# Web:
# https://sid-500.com

[CmdletBinding()]

param

(

[Parameter(Position=0,Mandatory=$true,Helpmessage = 'Enter Path to the Roaming Profiles Root Directory')]
$Path

)

$ErrorActionPreference="SilentlyContinue"

Get-ChildItem $Path -Recurse |
ForEach-Object {

takeown /f $_.FullName /a
icacls $_.Fullname /grant "administrators:(OI)(CI)F" /t

}
}

Make it permanent

Copy this code into your PowerShell ISE session and run the code. Then type the command and have fun with it. Or download it here:

Grant-RoamingProfilesAccess

If you want to make the function permanently available, so that the function is there every time you start PowerShell, you have to create a folder in C:\Program Files\WindowsPowerShell\Modules. Name it Grant-RoamingProfilesAccess. Then save the code as .psm1 file in that folder. The screenshot below will help you.

Unbenannt.PNG

12 replies »

  1. Hallo Patrick!

    Von der Idee her ist Dein Script genau was ich brauche und auf der Suche nach einer Loesung zu genau dem Problem, dass Du beschriebst, habe ich es zufaellig gefunden. Ich habe es hinbekommen es global auf dem Server verfuegbar zu machen, aber es loest mein Problem noch nicht gaenzlig, da versteckte Dateien und Ordner uebergangen werden. Ich bin Programmierer und habe auch ein wenig Erfahrunhg auf der Linux- und Windows-Konsole aber habe leider nach vielem recherchieren keine Loesung gefunden. Was nach Ausfuehrung Deiner Funktion noch fehlt, ist das was das GUI erledigt, wenn man “Replace all child object permission entries with inheritable permission entries from this object” anwendet.
    Egal was ich in Deinem Script geaendert habe, es hat die Angelegenheit nur verkompliziert, bzw. sind die Rechte des Profileigentuemers entfernt worden. Hast Du vielleicht einen Rat fuer mich, wie man das Script aendern muss, damit auch versteckte Ordner mit einbezogen werden bzw. die Rechte des Hauptordners auf alle Dateien und Verzeichnisse inclusive versteckter Verzeichnisse vererbt werden?

    Viele Gruesse von den Philippinen
    Sash

    Like

    • Hallo!
      Danke für die Info. Ich habe leider keinen Tipp. Bin eher am überlegen das Skript wieder offline zu nehmen, da ich schon von mehreren Seiten gehört habe, dass es Probleme gibt.
      Liebe Grüße

      Like

      • Hallo Patrick,

        ich habe das Problem, dass verrsteckte Dateien und Verzeichnisse uebergangen werden, loesen konnen. Und zwar lag es daran, dass Get-ChildItem diese schlicht ignoriert, wenn man nicht den -Force Schalter aktiviert. Ansonsten lasse ich Dein Script genau so laufen, wie Du es veroeffentlicht hast und es tut genau was es soll. Vielen Dank!

        Gruss,
        Sash

        Like

  2. Hi Patrick, I have some bad experience when take ownership of the users roaming profile folder using other script. The users will have problem signing in to their computer. They will log in to “temporary profile”. Maybe I need to test this script first. Thanks

    Like

  3. Hallo,
    leider erhalte ich bei Ausführung des Scrips folgenden Fehler:

    ERFOLGREICH: Die Gruppe “Administratoren” ist jetzt der Besitzer der Datei
    E:\Profile\benutzername.V6″ .
    administrators: Zuordnungen von Kontennamen und Sicherheitskennungen wurden nicht durchgeführt.
    0 Dateien erfolgreich verarbeitet, bei 1 Dateien ist ein Verarbeitungsfehler aufgetreten.

    Zugriff auf die Profile durch Administratoren weiterhin nicht möglich.
    Wo könnte der Fehler liegen? (Windows Server 2016)

    Like

  4. function Grant-RoamingProfilesAccess {

    # .SYNOPSIS
    # Grant-RoamingProfilesAccess is an advanced Powershell function. It takes ownership of the users roaming profiles folders and grants the administrators group full access.

    # .DESCRIPTION
    # Uses takeown and icacls. Define the path to the roaming profiles root directory.

    # .PARAMETER
    # Path
    c:\profile2\

    # .EXAMPLE
    Grant-RoamingProfilesAccess -Path C:\Profile2\

    # .NOTES
    # Author: Patrick Gruenauer
    # Web:
    # https://sid-500.com

    [CmdletBinding()]

    param

    (

    [Parameter(Position=0,Mandatory=$true,Helpmessage = ‘C:\Profile2\’)]
    $Path

    )

    $ErrorActionPreference=”SilentlyContinue”

    Get-ChildItem $Path -Recurse |
    ForEach-Object {

    takeown /f $_.FullName /a
    icacls $_.Fullname /grant “administrators:(OI)(CI)F” /t

    }
    }

    this is not working for me can u see what i did wrong?

    Like

  5. Patrick do you tell me what is and purpose of roaming profiles. What does mean when you say roaming profiles. Do you mean roaming profiles store my files and folders on server intend on my local pc or laptop

    Like

      • Hi Patrick – thank you for sharing!

        Have a little question for yourself in regards to the script.

        If i only wanted to run this on a particular sub folder or a set of folders how would i proceed with this?

        As i do not want to remove all Roaming Profile Folder and only need to remove around 15 is there anyway around this – i thought if i create a script now it will save me time and effort doing it in future plus leaning something new always excites me 🙂

        Awaiting in anticipation for a response – thank you in advance.

        Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.