Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for login_set_default_printer.ps

(view source code of login_set_default_printer.ps as plain text)

  1. $Error.Clear( )
  2. $OldProgressPreference = $ProgressPreference
  3. $ProgressPreference = "SilentlyContinue"
  4. # Cmdlet for WMI queries changed in PowerShell version 6
  5. # Use 'ShareName' instead of 'Name' for network printers
  6. if ( $PSVersionTable.PSVersion.Major -lt 6 ) {
  7. 	Get-WmiObject -Class Win32_Printer -Filter "Name='HP LaserJet 4'" | Invoke-WmiMethod -Name SetDefaultPrinter
  8. } else {
  9. 	Get-CimInstance -ClassName Win32_Printer -Filter "Name='HP LaserJet 4'" | Invoke-CimMethod -Name 'SetDefaultPrinter'
  10. }
  11. $ProgressPreference = $OldProgressPreference
  12. if ( $Error ) {
  13. 	Write-Host "Failed to make 'HP LaserJet 4' the default printer"
  14. 	Write-Host "Error: $_"
  15. }

page last uploaded: 2021-01-27