Main example
List instances
# All instances of Win32_PrinterDriver, with the main properties
Get-CimInstance -ClassName Win32_PrinterDriver |
Select-Object -Property Name, Description, Status, Version, StartMode, InstallDateExamples
Filter with WQL
# WQL filter evaluated by the provider: only the instances where Started is TRUE
Get-CimInstance -ClassName Win32_PrinterDriver -Filter 'Started = TRUE' |
Select-Object -Property Name, Description, Status, Version, StartMode, InstallDateThe filter is evaluated by the WMI provider: less data is transferred than with Where-Object.
Query a remote computer (CIM session)
review before running# Name of the remote computer
$computerName = 'SERVER01'
# The CIM session (WSMan by default) can be reused for several queries
$cimSession = New-CimSession -ComputerName $computerName
try {
Get-CimInstance -CimSession $cimSession -ClassName Win32_PrinterDriver |
Select-Object -Property Name, Description, Status, Version, StartMode, InstallDate
} finally {
Remove-CimSession -CimSession $cimSession
}WSMan (WinRM) is used by default. For a host without WinRM, create the session with -SessionOption (New-CimSessionOption -Protocol Dcom). Add -Credential to use another account.
Show the class structure
# Class structure: properties, types and flags (Key, ReadOnly…)
$cimClass = Get-CimClass -ClassName Win32_PrinterDriver
$cimClass.CimClassProperties |
Select-Object -Property Name, CimType, Flags
# Methods of the class
$cimClass.CimClassMethods |
Select-Object -Property Name, ReturnTypeProperties
| Name | Type | Access | Description | |||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Caption# | string | read | Short description of the object—a one-line string. Code | |||||||||||||||||||||||||||||||||||||||
| ConfigFile# | string | read | Configuration file for this printer driver. Example: "pscrptui.dll" Code | |||||||||||||||||||||||||||||||||||||||
| CreationClassName# key | string | read | Name of the class or the subclass used in the creation of an instance. When used with the other key properties of this class, this property allows all instances of this class and its subclasses to be uniquely identified. Code | |||||||||||||||||||||||||||||||||||||||
| DataFile# | string | read | Data file for this printer driver. Example: "qms810.ppd" Code | |||||||||||||||||||||||||||||||||||||||
| DefaultDataType# | string | read | Default data type for this printer driver. Example: "EMF" Code | |||||||||||||||||||||||||||||||||||||||
| DependentFiles# | string[] | read | Array of dependent files for this printer driver. Code | |||||||||||||||||||||||||||||||||||||||
| Description# | string | read | Comment that describes the link. Code | |||||||||||||||||||||||||||||||||||||||
| DriverPath# | string | read | Path for this printer driver. Example: "C:\\drivers\\pscript.dll" Code | |||||||||||||||||||||||||||||||||||||||
| FilePath# | string | read/write | Path to the INF file being used. Example: "c:\\temp\\driver" CodeWarning. Changes the system: check with -WhatIf first. An elevated console is often required. | |||||||||||||||||||||||||||||||||||||||
| HelpFile# | string | read | Help file for this printer driver. Example: "pscrptui.hlp" Code | |||||||||||||||||||||||||||||||||||||||
| InfName# | string | read/write | Name of the INF file being used. The default is to use an operating system provided printer INF file. A different file name is used if the driver is provided directly by the manufacturer of the printer and not the operating system. CodeWarning. Changes the system: check with -WhatIf first. An elevated console is often required. | |||||||||||||||||||||||||||||||||||||||
| InstallDate# | datetime | read | Date and time the object is installed. This property does not require a value to indicate that the object is installed. Code | |||||||||||||||||||||||||||||||||||||||
| MonitorName# | string | read | Name of the monitor for this printer driver. Example: "PJL monitor" Code | |||||||||||||||||||||||||||||||||||||||
| Name# key | string | read | Driver name for this printer. This is a compound key composed of the Name, Version, and SupportedPlatform values. Code | |||||||||||||||||||||||||||||||||||||||
| OEMUrl# | string | read | World Wide Web (WWW) link to the printer manufacturer's website. Note that this property is not populated when the Win32.inf file is used, and is only applicable for drivers provided directly from the manufacturer. Code | |||||||||||||||||||||||||||||||||||||||
| Started# | boolean | read | If TRUE, the service is started. If FALSE, the service is stopped. Code | |||||||||||||||||||||||||||||||||||||||
| StartMode# | string | read | Start mode of the service is automatically started by an operating system, or only started when requested. The following are possible values: "Automatic" "Manual" Values (2)
Code | |||||||||||||||||||||||||||||||||||||||
| Status# | string | read | Current status of the object. Various operational and nonoperational statuses can be defined. Operational statuses include: "OK", "Degraded", and "Pred Fail" (an element, such as a SMART-enabled hard disk drive, may be functioning properly but predicting a failure in the near future). Nonoperational statuses include: "Error", "Starting", "Stopping", and "Service". The latter, "Service", can apply during mirror-resilvering of a disk, reload of a user permissions list, or other administrative work. Not all such work is online, yet the managed element is neither "OK" nor in one of the other states. Values include the following: Values (12)
Code | |||||||||||||||||||||||||||||||||||||||
| SupportedPlatform# | string | read/write | Operating environments that the driver is intended for. Example: "Windows NT x86". CodeWarning. Changes the system: check with -WhatIf first. An elevated console is often required. | |||||||||||||||||||||||||||||||||||||||
| SystemCreationClassName# key | string | read | Scoping system's creation class name. Code | |||||||||||||||||||||||||||||||||||||||
| SystemName# key | string | read | Name of the system that hosts this service. Code | |||||||||||||||||||||||||||||||||||||||
| Version# | uint16 | read/write | Operating system version for the printer driver. Values (1)
CodeWarning. Changes the system: check with -WhatIf first. An elevated console is often required. |
Methods
AddPrinterDriver #
Creates a new printer driver.
uint32 AddPrinterDriver([in] Win32_PrinterDriver DriverInfo);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| DriverInfo | Win32_PrinterDriver | in | An instance of the Win32_PrinterDriver class that represents the printer driver. |
Return values
| Value | Label | Description |
|---|---|---|
| 0 | Success. | |
| 5 | Access denied. | |
| 87 | The parameter is incorrect. May occur when the object is not correctly filled or when driver cannot be found in the system. Alternately, the name attribute may be different than the model specified in the .inf file. Or, there may be a missing backslash ("\") on a PathFile attribute. | |
| 1797 | The printer driver is unknown. |
Call the AddPrinterDriver method
review before running# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_PrinterDriver -Filter "Name = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'AddPrinterDriver'
Arguments = @{ DriverInfo = $null }
WhatIf = $true # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters
# With -WhatIf nothing runs and no result is returned
if ($result) {
$returnValueName = @{
0 = 'Success'
5 = 'Access denied'
87 = 'The parameter is incorrect'
1797 = 'The printer driver is unknown'
}
$returnValueName[[int]$result.ReturnValue]
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
StartService #
Starts print service.
uint32 StartService();Return values
| Value | Label | Description |
|---|---|---|
| 0 | Service successfully started. | |
| 1 | Request not supported. |
Call the StartService method
review before running# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_PrinterDriver -Filter "Name = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'StartService'
WhatIf = $true # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters
# With -WhatIf nothing runs and no result is returned
if ($result) {
$returnValueName = @{
0 = 'Service successfully started'
1 = 'Request not supported'
}
$returnValueName[[int]$result.ReturnValue]
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
StopService #
Stops print service.
uint32 StopService();Return values
| Value | Label | Description |
|---|---|---|
| 0 | Service successfully stopped. | |
| 1 | Request not supported. |
Call the StopService method
review before running# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_PrinterDriver -Filter "Name = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'StopService'
WhatIf = $true # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters
# With -WhatIf nothing runs and no result is returned
if ($result) {
$returnValueName = @{
0 = 'Service successfully stopped'
1 = 'Request not supported'
}
$returnValueName[[int]$result.ReturnValue]
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
Remarks
The Win32_PrinterDriver class is derived from CIM_Service which derives from CIM_LogicalElement.
Users can uninstall a printer driver by deleting a corresponding instance of this class. To do so, the calling process must have the SeLoadDriverPrivilege privilege set to delete an instance of this class.
Inheritance
Superclass chain
- CIM_ManagedSystemElement
- CIM_LogicalElement
- CIM_Service
- Win32_PrinterDriver
Known subclasses
No known subclass.
Requirements
- Namespace
- root/cimv2
- Minimum client
- Windows Vista
- Minimum server
- Windows Server 2008
- MOF file
- Win32_Printer.mof
- DLL
- CIMWin32.dll
Microsoft source
Descriptions, properties and methods come from the Microsoft documentation (MicrosoftDocs/win32 repository), published under the CC BY 4.0 licence. Formatting and translations are specific to this site; the PowerShell examples are written for it.