06 April 2015

Get Default Printer

The new and updated Default Printer report is located here.

This script will find the default printer of a logged on user and write it to a text file named DefaultPrinter.txt in the %APPDATA% folder. I have this script run as a package in SCCM on a reoccurring weekly basis. This keeps the file up to date in the event a user needs a new machine or a new profile.

You can download the file from here: GetDefaultPrinter.ps1



 <#  
 .SYNOPSIS  
   Get Default Printer  
 .DESCRIPTION  
   Gets the default printer and writes the printer to a text file in the %APPDATA% folder. If  
   this is executed through SCCM, it must be run as the user.  
 .Author  
   Mick Pletcher  
 .Date  
   06 April 2015  
 .EXAMPLE  
   powershell.exe -executionpolicy bypass -file GetDefaultPrinter.ps1  
 #>  
   
 #Declare Global Variables  
 Set-Variable -Name DefaultPrinter -Scope Global -Force  
   
 cls  
 If ((Test-Path $env:APPDATA"\DefaultPrinter.txt") -eq $true) {  
      Remove-Item -Path $env:APPDATA"\DefaultPrinter.txt" -Force  
 }  
 $DefaultPrinter = Get-WmiObject -Class win32_printer -ComputerName "localhost" -Filter "Default='true'" | Select-Object ShareName  
 Write-Host "Default Printer: " -NoNewline  
 If ($DefaultPrinter.ShareName -ne $null) {  
      $DefaultPrinter.ShareName | Out-File -FilePath $env:APPDATA"\DefaultPrinter.txt" -Force -Encoding "ASCII"  
      Write-Host $DefaultPrinter.ShareName  
 } else {  
      $DefaultPrinter = "No Default Printer"  
      $DefaultPrinter | Out-File -FilePath $env:APPDATA"\DefaultPrinter.txt" -Force -Encoding "ASCII"  
      Write-Host $DefaultPrinter  
 }  
   
 #Cleanup Global Variables  
 Remove-Variable -Name DefaultPrinter -Scope Global -Force  
   

Related Posts:

  • Cleaning up old systems in Active Directory, SCCM, and Antivirus Every place I have worked, there has been the issue of systems being in SCCM, AD, and antivirus that no longer existed. The is often caused by systems being overlooked when a user departs the company, a laptop that gets put… Read More
  • Import and Apply Local GPOs This script will import and apply a local GPO using the local GPO utility, ImportRegPol.exe, located here. The script is a wrapper that makes implementing this utility a snap. All that has to be done is to use the Micr… Read More
  • Replicate Permissioning Here is a script I have written that will replicate the permissions between two folders including all subfolders and file permissions. Execute the script and you will be prompted for the source and destination folders. It w… Read More
  • OS Detection Recently, we added the Windows 8.1 operating system to the company domain. I ran into the problem of deploying Adobe Flash Player to these systems because the ActiveX does not get installed. The issue came up in SCCM where … Read More
  • List all Local Administrators on a Computer I wrote this script to generate a list of local administrators on a PC. It saves the output to a text file at a central repository. The text file is named the computer name and contains a listing of all the local administr… Read More

0 comments:

Post a Comment