Script Repository

Remove permissions for Adaxes service administrators to access user's home directory

April 27, 2016

The script can be used in Business Rules, Scheduled Tasks and Custom Commands to remove any permissions assigned to Adaxes service administrators to access a user's home directory.

Note: By default, if a home directory is created for a user via Adaxes, the default service administrator will be assigned Full Access permissions for the home directory.

If you remove the permissions, Adaxes will be unable to perform operations with the home directory, for example, move or delete it.
Edit Remove
# Get home directory path
    $homeDirectoryPath = $Context.TargetObject.Get("homeDirectory")
    $Context.LogMessage("The user doesn't have a home directory", "Warning")

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

# Get Security Identifiers 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)

# Get home directory Access Control List
$acl = Get-Acl -Path $homeDirectoryPath

# Find and remove the default service administrator from the Access Control List
$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)))
        # 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")

# Assign the modified Access Control List
$folder = Get-Item $homeDirectoryPath

Comments ( 0 )
No results found.
Leave a comment

Related Scripts