Public/Add-SpecPrinterPermission.ps1
Function Add-SpecPrinterPermission { <# .SYNOPSIS This function adds additional permissions to the security descriptor definition language (SDDL) of a specified printer. .DESCRIPTION The Add-SpecPrinterPermission function modifies the SDDL permissions of a specific printer by adding an additional SDDL permission string to its existing permissions. .PARAMETER Printer The name of the printer to which you want to add permissions. .PARAMETER OriginalPrinterSDDL The original SDDL permission string of the printer before adding the new permissions. .PARAMETER SDDLToAdd The additional SDDL permission string to be added to the original permissions. .EXAMPLE Add-SpecPrinterPermission -Printer "Printer1" -OriginalPrinterSDDL "D:P(A;OICI;GA;;;BA)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;WD)" -SDDLToAdd "(A;;RPWPDTLOCRRC;;;PS)" This example adds the SDDL permission "(A;;RPWPDTLOCRRC;;;PS)" to the printer "Printer1", where "PS" represents a security principal. .NOTES Author: andy.naftel Version: 1.0 - Original Code 1.1 - [owen.heaume] Add comment-based help - [owen.heaume] Added error handling and return codes 1.2 - [owen.heaume' Refactor to remove redundant code. - This function requires administrative privileges to modify printer permissions. - The function retrieves the current printer permissions using the Get-SpecPrinterPermissions cmdlet. .LINK Get-SpecPrinterPermission #> [CmdletBinding()] param ( [Parameter(Mandatory = $True)] $Printer, [Parameter(Mandatory = $True)] $OriginalPrinterSDDL, [Parameter(Mandatory = $True)] $SDDLToAdd ) $NewSDDL = $OriginalPrinterSDDL + $SDDLToAdd Write-Verbose "Updating current printer SDDL permissions for $Printer" try { Set-Printer -Name $Printer -PermissionSDDL $NewSDDL -ErrorAction Stop -ErrorVariable x write-verbose "Successfully updated current printer SDDL permissions for $Printer" return 100 } catch { Write-warning "Error updating current printer SDDL permissions for $Printer" Write-Warning "The error was: $x" return 103 } } |