Book Image

Windows Server 2016 Automation with PowerShell Cookbook - Second Edition

By : Thomas Lee, Ed Goad
Book Image

Windows Server 2016 Automation with PowerShell Cookbook - Second Edition

By: Thomas Lee, Ed Goad

Overview of this book

This book showcases several ways that Windows administrators can use to automate and streamline their job. You'll start with the PowerShell and Windows Server fundamentals, where you'll become well versed with PowerShell and Windows Server features. In the next module, Core Windows Server 2016, you'll implement Nano Server, manage Windows updates, and implement troubleshooting and server inventories. You'll then move on to the Networking module, where you'll manage Windows network services and network shares. The last module covers Azure and DSC, where you will use Azure on PowerShell and DSC to easily maintain Windows servers.
Table of Contents (21 chapters)
Title Page
Credits
About the Author
Acknowledgment
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Printing a test page on a printer


From time to time, you may wish to print a test page on a printer, for example, after changing toner or printer ink, or after changing the print driver (as shown in the Changing printer drivers recipe). In those cases, the test page helps you to ensure that the printer is working properly.

Getting ready

For this recipe, you print a test page on the Sales Group object's LaserJet printer, as updated by the Changing printer drivers recipe.

How to do it...

  1. Get the printer objects from WMI:
$Printers = Get-CimInstance -ClassName 
                  Win32_Printer
  1. Display the number of printers defined:
'{0} Printers defined on this system' `
           -f $Printers.Count
  1. Get the Sales Group printer:
$Printer = $Printers | 
                  Where-Object Name -eq "SGCP1"
  1. Display the printer's details:
$Printer | Format-Table -AutoSize
  1. Print a test page:
Invoke-CimMethod -InputObject $Printer `                   -MethodName PrintTestPage

How it works...

In step 1, you use Get-CimInstance...