To check printers using PowerShell, you can use the Get-Printer cmdlet.
1. Listing all installed printers:
To get a list of all printers installed on your local machine, open PowerShell and execute the following command:
Get-Printer
2. Viewing specific printer properties:
If you want to see specific properties of the printers, you can pipe the output to Select-Object. For example, to see the name and status of each printer:
Get-Printer | Select-Object Name, PrinterStatus
3. Filtering printers based on criteria:
You can filter the list of printers based on various criteria using Where-Object. For instance, to see only printers with a "Normal" status:
Get-Printer | Where-Object PrinterStatus -eq "Normal"
4. Checking printers on a remote computer:
To check printers on a remote computer (e.g., a print server), use the -ComputerName parameter:
Get-Printer -ComputerName "RemoteServerName"
5. Getting detailed information:
For a more detailed view of printer configurations, you can use Format-List:
Get-Printer | Format-List *
This will display all properties of each printer in a list format.
To share a printer using PowerShell, the Set-Printer cmdlet is used. This cmdlet allows for configuring various printer settings, including sharing status.
Sharing a Local Printer:
Set-Printer -Name "PrinterName" -Shared $True -ShareName "ShareName"
Replace "PrinterName" with the exact name of the printer you want to share.
Replace "ShareName" with the desired name for the shared printer on the network.
Sharing a Printer on a Remote Computer:
Set-Printer -ComputerName "RemoteComputerName" -Name "PrinterName" -Shared $True -ShareName "ShareName"
Replace "RemoteComputerName" with the name or IP address of the remote computer where the printer is installed.
Replace "PrinterName" with the exact name of the printer on the remote computer.
Replace "ShareName" with the desired name for the shared printer on the network.
Verifying the Printer Share:
After running the Set-Printer command, you can verify the share status using the Get-Printer cmdlet:
Get-Printer -Name "PrinterName" | Select-Object Name, Shared, ShareName
This command will display the printer's name, whether it is shared, and its share name.
To connect to an already shared network printer on a Windows PC using PowerShell, the recommended command for modern systems is Add-Printer.
PowerShell Command to Add a Shared Printer
You will need the network path to the shared printer in the standard UNC format: \\ServerName\ShareName.
Run the following command in a standard or elevated PowerShell session, replacing "\\ServerName\ShareName" with your printer's actual network path:
powershell
Add-Printer -ConnectionName "\\ServerName\ShareName"
Use code with caution.
Alternative Method (Older Systems or Specific Needs)
For compatibility with very old scripts, or if Add-Printer doesn't work for some reason, the .NET Framework object method is available, but the Add-Printer cmdlet is generally preferred.
Prerequisites
Network Connectivity: The PC must be able to reach the host computer (print server) over the network.
Permissions: The user running the command needs appropriate network permissions to access the share.
Drivers: Windows will typically attempt to automatically download and install the required print drivers from the print server when you execute the Add-Printer -ConnectionName command.
Verify the Connection
After running the command, you can check if the printer was added successfully using Get-Printer:
powershell
Get-Printer -Name "ShareName"
Use code with caution.
You should also see the new printer listed in your Windows "Printers & Scanners" settings.