Remove-PrinterDriver
Print Management: Deletes a printer driver from the specified computer.
#Requires -Version 5.1
#Requires -Modules PrintManagement
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[string]$DriverName,
[string]$ComputerName,
[pscredential]$AccessAccount,
[switch]$RemoveFromDriverStore
)
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 }
if ($RemoveFromDriverStore) {
Remove-PrinterDriver -CimSession $cim -Name $DriverName -ComputerName $ComputerName -RemoveFromDriverStore -ErrorAction Stop | Out-Null
}
else {
Remove-PrinterDriver -CimSession $cim -Name $DriverName -ComputerName $ComputerName -ErrorAction Stop | Out-Null
}
Write-Output "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") Printer driver $DriverName removed from $ComputerName"
}
catch { throw }
finally { if ($null -ne $cim) { Remove-CimSession $cim -ErrorAction SilentlyContinue } }
}Name of the printer driver to remove.
Name of the computer from which to remove the printer driver.
User account that has permission to perform this action.
Off
Remove the printer driver from the driver store.