Script repository
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
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
Support
Hello Dennis,
For troubleshooting purposes, please, send us (support@adaxes.com) a screenshot of the Multi-server environment dialog. The dialog displays how many Adaxes services you have and what their versions are. For information on how to view it, see https://www.adaxes.com/help/MultiServerEnvironment.