Script repository
The script creates a Remote Desktop Services profile folder for a user on the file system. To execute the script, use a buniness rule, scheduled task or custom command configured for the User object type.
$homeFolderPath = $Context.TargetObject.TerminalServicesHomeDirectory
# Create folder on the file system.
try
{
$homeFolder = New-Item -ItemType directory -Path $homeFolderPath -ErrorAction Stop
}
catch
{
$Context.LogMessage($_.Exception.Message, "Error")
return
}
# Get user SID.
$userSidBinary = $Context.TargetObject.Get("objectSid")
$userSid = New-Object System.Security.Principal.SecurityIdentifier($userSidBinary, 0)
# Grant user full control permissions for the folder.
$homeFolderACL = Get-Acl $homeFolder
$acl = New-Object System.Security.AccessControl.FileSystemAccessRule($userSid,"FullControl","ContainerInherit,ObjectInherit","None","Allow")
$homeFolderACL.AddAccessRule($acl)
Set-Acl -path $homeFolder $homeFolderACL
Comments 0
You must be signed in to comment.