Private/Get-SpecPrinterPermission.ps1

Function Get-SpecPrinterPermission {
    <#
    .SYNOPSIS
    Retrieves the current SDDL permissions for a printer.
 
    .DESCRIPTION
    The Get-SpecPrinterPermissions function retrieves the current SDDL permissions for a printer. The SDDL string is a text string that describes a security descriptor. The function takes a single parameter, the name of the printer.
 
    .PARAMETER Printer
    The name of the printer. This parameter is mandatory.
 
    .EXAMPLE
    Get-SpecPrinterPermission "MyPrinter"
 
    This command will retrieve the current SDDL permissions for the printer named "MyPrinter".
 
    .OUTPUTS
    The function returns a string containing the SDDL permissions for the printer.
 
    It may also return one of the following error codes:
    101 - Unable to retrieve current printer SDDL permissions
    102 - Unable to retrieve current printer SDDL permissions. Printer not found.
 
    .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
    #>


    [cmdletbinding()]
    param (
        [Parameter(Mandatory = $True)]
        $Printer
    )

    If ($Printer -iin (Get-Printer).Name) {

        Write-Verbose "Retrieving current printer SDDL permissions for $Printer"
        try {
            $SDDL = Get-Printer -Full -Name $Printer | Select-Object PermissionSDDL -ExpandProperty PermissionSDDL
            write-verbose "Current printer SDDL permissions successfully retrieved for $Printer"
            Return $SDDL
        } catch {
            Write-Warning "Unable to retrieve current printer SDDL permissions for $Printer"
            Return 101
        }
    } else {
        Write-Warning "Unable to retrieve current printer SDDL permissions for $Printer. Printer not found."
        Return 102
    }
}