Created
January 23, 2017 19:46
-
-
Save dotps1/61ce00fec80d3558baebe94220678d02 to your computer and use it in GitHub Desktop.
Set Manage Documents permission on a Print Server.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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