Skip to content

Set-PrintConfiguration

Print Management: Updates printer configuration

#Requires -Version 5.1
#Requires -Modules PrintManagement

[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)][string]$PrinterName,
    [string]$Comment,
    [string]$Location,
    [bool]$Shared,
    [string]$ComputerName,
    [pscredential]$AccessAccount
)

Process {
    try {
        if ([System.String]::IsNullOrWhiteSpace($ComputerName)) { $ComputerName = [System.Net.DNS]::GetHostByName('').HostName }
        $cim = if ($null -eq $AccessAccount) { New-CimSession -ComputerName $ComputerName -ErrorAction Stop } else { New-CimSession -ComputerName $ComputerName -Credential $AccessAccount -ErrorAction Stop }
        $cmdArgs = @{ ErrorAction = 'Stop'; CimSession = $cim; ComputerName = $ComputerName; Name = $PrinterName; Confirm = $false }
        if ($PSBoundParameters.ContainsKey('Comment')) { $cmdArgs.Add('Comment', $Comment) }
        if ($PSBoundParameters.ContainsKey('Location')) { $cmdArgs.Add('Location', $Location) }
        if ($PSBoundParameters.ContainsKey('Shared')) { $cmdArgs.Add('Shared', $Shared) }
        $result = Set-Printer @cmdArgs | Select-Object *
        if ($null -ne $result) { $result | Add-Member -NotePropertyName Timestamp -NotePropertyValue (Get-Date -Format "yyyy-MM-dd HH:mm:ss") -PassThru -Force }
    }
    catch { throw }
    finally { if ($null -ne $cim) { Remove-CimSession $cim -ErrorAction SilentlyContinue } }
}

Printer to configure

New comment

New location

Share/unshare the printer

Computer hosting the printer

Optional credential

An interactive directory of PowerShell scripts.