Win32_PrinterShare

The Win32_PrinterShare association WMI class relates a local printer and the share that represents it as it is viewed over a network.

The Win32_PrinterShare association WMI class relates a local printer and the share that represents it as it is viewed over a network.

Methods

Win32_PrinterShare has no methods.

Properties

Win32_PrinterShare returns 2 properties:

'Antecedent','Dependent'

Unless explicitly marked as writeable, all properties are read-only. Read all properties for all instances:

Get-CimInstance -ClassName Win32_PrinterShare -Property *

Most WMI classes return one or more instances.

When Get-CimInstance returns no result, then apparently no instances of class Win32_PrinterShare exist. This is normal behavior.

Either the class is not implemented on your system (may be deprecated or due to missing drivers, i.e. CIM_VideoControllerResolution), or there are simply no physical representations of this class currently available (i.e. Win32_TapeDrive).

Antecedent

KEY PROPERTY WIN32_PRINTER

Reference to the instance representing the local printer shared in this association.

Get-CimInstance -ClassName Win32_PrinterShare | Select-Object -Property Antecedent, Dependent

Dependent

KEY PROPERTY WIN32_SHARE

Reference to the instance representing the share of the printer in this association.

Get-CimInstance -ClassName Win32_PrinterShare | Select-Object -Property Antecedent, Dependent

Examples

List all instances of Win32_PrinterShare
Get-CimInstance -ClassName Win32_PrinterShare

Learn more about Get-CimInstance and the deprecated Get-WmiObject.

View all properties
Get-CimInstance -ClassName Win32_PrinterShare -Property *
View key properties only
Get-CimInstance -ClassName Win32_PrinterShare -KeyOnly

Selecting Properties

To select only some properties, pipe the results to Select-Object -Property a,b,c with a comma-separated list of the properties you require. Wildcards are permitted.

Get-CimInstance always returns all properties but only retrieves the ones that you specify. All other properties are empty but still present. That’s why you need to pipe the results into Select-Object if you want to limit the visible properties, i.e. for reporting.

Selecting Properties

The code below lists all available properties. Remove the ones you do not need:

$properties = 'Antecedent',
              'Dependent'
Get-CimInstance -ClassName Win32_PrinterShare | Select-Object -Property $properties
Limiting Network Bandwidth

If you work remotely, it makes sense to limit network bandwidth by filtering the properties on the server side, too:

Get-CimInstance -Class Win32_PrinterShare -Property $property | 
Select-Object -Property $property

Selecting Instances

To select some instances, use Get-CimInstance and a WMI Query. The wildcard character in WMI Queries is % (and not “*”).

The parameter -Filter runs a simple query.

Listing all instances where the property Caption starts with “A”
Get-CimInstance -Class Win32_PrinterShare -Filter 'Caption LIKE "a%"' 
Using a WQL Query

The parameter -Query uses a query similar to SQL and combines the parameters -Filter and -Property. This returns all instances where the property Caption starts with “A”, and returns the properties specified:

Get-CimInstance -Query "SELECT Dependent, Antecedent FROM Win32_PrinterShare WHERE Caption LIKE 'a%'"

Any property you did not specify is still present but empty. You might need to use Select-Object to remove all unwanted properties:

Get-CimInstance -Query "SELECT Dependent, Antecedent FROM Win32_PrinterShare WHERE Caption LIKE 'a%'" | Select-Object -Property Dependent, Antecedent

Accessing Remote Computers

To access remote systems, you need to have proper permissions. User the parameter -ComputerName to access one or more remote systems.

Authenticating as Current User
# one or more computer names or IP addresses:
$list = 'server1', 'server2'

# authenticate with your current identity:
$result = Get-CimInstance -ClassName Win32_PrinterShare -ComputerName $list 
$result
Authenticating as Different User

Use a CIMSession object to authenticate with a new identity:

# one or more computer names or IP addresses:
$list = 'server1', 'server2'

# authenticate with a different identity:
$cred = Get-Credential -Message 'Authenticate to retrieve WMI information:'
$session = New-CimSession -ComputerName $list -Credential $cred

$result = Get-CimInstance Win32_PrinterShare -CimSession $session

# remove the session after use (if you do not plan to re-use it later)
Remove-CimSession -CimSession $session

$result

Learn more about accessing remote computers.

Requirements

To use Win32_PrinterShare, the following requirements apply:

PowerShell

Get-CimInstance was introduced with PowerShell Version 3.0, which in turn was introduced on clients with Windows 8 and on servers with Windows Server 2012.

If necessary, update Windows PowerShell to Windows PowerShell 5.1, or install PowerShell 7 side-by-side.

Operating System

Win32_PrinterShare was introduced on clients with Windows Vista and on servers with Windows Server 2008.

Namespace

Win32_PrinterShare lives in the Namespace Root/CIMV2. This is the default namespace. There is no need to use the -Namespace parameter in Get-CimInstance.

Implementation

Win32_PrinterShare is implemented in CIMWin32.dll and defined in Win32_Printer.mof. Both files are located in the folder C:\Windows\system32\wbem:

explorer $env:windir\system32\wbem
notepad $env:windir\system32\wbem\Win32_Printer.mof