Script repository

Remove permissions for Adaxes service administrators to access user home directory

Updated on: Jan 18, 2026, Views: 4777

Miscellaneous

The script removes any permissions assigned to Adaxes service administrators to access a user home directory. To execute the script, create a business rule, custom command or scheduled task configured for the User object type.

# Get home directory path.
try
{
    $homeDirectoryPath = $Context.TargetObject.Get("homeDirectory")
}
catch
{
    $Context.LogMessage("The user doesn't have a home directory", "Warning")
    return
}

# Bind to the 'Configuration Set Settings' container.
$configSetSettingsPath = $Context.GetWellKnownContainerPath("ConfigurationSetSettings")
$configSetSettings = $Context.BindToObject($configSetSettingsPath)

# Get SIDs of all service administrators.
$adminManager = $configSetSettings.AdministratorManager
$adminsSidsBytes = $adminManager.Administrators
$adminSids = New-Object "System.Collections.Generic.HashSet[System.String]"
foreach ($sidBytes in $adminsSidsBytes)
{
    $sid = New-Object "Softerra.Adaxes.Adsi.Sid" @($sidBytes, 0)
    [void]$adminSids.Add($sid)
}

# Get home directory ACL.
$acl = Get-Acl -Path $homeDirectoryPath

# Find and remove the Adaxes service account from the ACL.
$accessRules = $acl.Access
for ($i = $accessRules.Count - 1; $i -ge 0; $i--)
{
    $accessRule = $accessRules[$i]
    $isInherited = $accessRule.IsInherited
    foreach ($identityReference in $accessRule.IdentityReference)
    {
        # Translate identity to SID.
        $sid = $identityReference.Translate("System.Security.Principal.SecurityIdentifier").Value
        if (!($adminSids.Contains($sid)))
        {
            continue
        }
        
        # Check if permission are inherited from a parent container.
        $userIdentity = $identityReference.Value
        $userPermissions = $identityReference
        if ($isInherited)
        {
            $Context.LogMessage("Cannot remove permissions '$userPermissions' for '$userIdentity' because access rights are inherited from a parent container", "Warning")
            continue
        }
        
        [void]$acl.RemoveAccessRule($accessRule)
    }
}

# Assign modified ACL.
$folder = Get-Item $homeDirectoryPath
$folder.SetAccessControl($acl)

Comments 2

You must be signed in to comment.

  • Dennis

    Dennis

    Hi,

    Does this script still work? When executing this we get the error:

    Method invocation failed because [System.IO.DirectoryInfo] does not contain a method named 'SetAccessControl'. Stack trace: at , : line 59

    Cheers,

    Dennis

Got questions?

Support Questions & Answers

We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.