Skip to content

Instantly share code, notes, and snippets.

@dotps1
Created January 23, 2017 19:46
Show Gist options
  • Save dotps1/61ce00fec80d3558baebe94220678d02 to your computer and use it in GitHub Desktop.
Save dotps1/61ce00fec80d3558baebe94220678d02 to your computer and use it in GitHub Desktop.
Set Manage Documents permission on a Print Server.
# Get the SID of the group to give Permissions to.
$sid = ([System.Security.Principal.NTAccount]"DOMAIN\GROUPNAME").Translate(
[System.Security.Principal.SecurityIdentifier]
)
# Build an Access Control Entry object giving the group the Manage Documents permission. 983088 is the access mask for Manage Documents only.
$ace = New-Object -TypeName System.Security.AccessControl.CommonAce -ArgumentList @(
@([System.Security.AccessControl.AceFlags]::ObjectInherit, [System.Security.AccessControl.AceFlags]::InheritOnly), [System.Security.AccessControl.AceQualifier]::AccessAllowed, 983088, $sid, $false, $null
)
# Build a Raw Security Descriptor Object from the binary data stored in the registry key property.
$rawSecurityDescriptor = New-Object -TypeName System.Security.AccessControl.RawSecurityDescriptor -ArgumentList @(
(Get-ItemPropertyValue -Path HKLM:\SYSTEM\CurrentControlSet\Control\Print -Name ServerSecurityDescriptor), 0
)
# Insert the ACE into the ACL.
$rawSecurityDescriptor.DiscretionaryAcl.InsertAce(
$rawSecurityDescriptor.DiscretionaryAcl.Count, $ace
)
# Convert the modified ACL back to binary.
[Void][Byte[]]$bytes[$rawSecurityDescriptor.BinaryLength]
$rawSecurityDescriptor.GetBinaryForm(
$bytes, 0
)
# Write the data back to the registry.
Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\Print -Name ServerSecurityDescriptor -Value $bytes
# Restart the Print Spooler.
Restart-Service -Name Spooler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment