Procedure details

The following steps describe how to generate PDF output from the ZonesReport.ps1 script.

  • You must have administrator privileges to perform these steps.
  • Unless otherwise noted, you perform the steps described here in the PowerShell console window.
  • In this example, the PDF printer that converts HTML to PDF is named “PDFCreator”. If the printer has a different name in your environment, use your printer’s name.
  1. Install PDFCreator from
  2. Generate HTML output from the ZonesReport.ps1 script by executing the following command in the PowerShell console:

    .\ZonesReport.ps1 | ConvertTo-Html -Head "<Style>$(Get-Content .\Report.css)</Style>" | Out-File c:\Reports\ZonesReport.html

    When you execute this command, the file c:\Reports\ZonesReport.html is created using the styles in Report.css.

  3. Specify PDFCreator as the default printer:

    1. Execute the following command to get all installed printers:

      $printers = gwmi win32_printer
    2. Run the following variable to list the printers:

    3. In the list of printers, note the position of the PDFCreator printer in the list. For example, in the following list of printers, PDFCreator is the sixth printer listed:

    4. Make PDFCreator the default printer. In this example, because PDFCreator is the sixth printer on the list, you would execute the following command:

    5. Verify that PDFCreator is the default printer by opening the Devices and Printers control panel. If PDFCreator is not the default printer, you can make it the default printer here.

  4. Configure auto-save printer settings as follows:

    • Change the auto-save directory to C:\Reports
    • Change the auto-save file name to ZonesReport
    • Enable the auto-save feature so that there will be no dialog prompts to ask for which file name to save

    Perform the following steps to configure the registry to implement these changes. These steps assume that the default registry path is HKCU:\Software\PDFCreator\Program. If your registry path is different, change these commands as appropriate for your environment.

    1. Execute the following command to change the auto-save directory to C:\Reports:

      Set-ItemProperty -Path "HKCU:\Software\PDFCreator\Program" 
      -Name "AutoSaveDirectory" -Value "C:\Reports"
    2. Execute the following command to change the auto-save file name to ZonesReport:

      Set-ItemProperty -Path "HKCU:\Software\PDFCreator\Program" 
      -Name "AutoSaveFileName" -Value "ZonesReport"
    3. Execute the following command to enable the auto-save feature:

      Set-ItemProperty -Path "HKCU:\Software\PDFCreator\Program" -Name "UseAutoSave" -Value "1"
  5. Use Internet Explorer to print the HTML file that you created in Step 2 on the default (PDFCreator) printer. This step results in the creation of the PDF file.

    The recommended way to perform this step is to create and run the following script in the PowerShell console window. The script performs the following tasks:

    • Creates an IE object and stores it into the variable $ie.
    • Sets IE output not to display on the screen. This part of the script is optional; if you want IE output to display, you can omit this section of the script.
    • Instructs the $ie object to read the HTML content from the location C:\Reports\ZonesReport.html (the HTML file that you created in Step 2).
    • Prints the content of $ie using default printer (PDFCreator), resulting in the generation of the PDF file.

    The recommended script is as follows:

    $ie = New-Object -com "InternetExplorer.Application"
    $ie.Visible = $false
    while ( $ie.busy ) { Start-Sleep -second 1 }
    while ( $ie.busy ) { Start-Sleep -second 1 }

    Note:   This script is specific to the example used in this procedure. If you changed any of the steps in this procedure because of differences in your environment, you might have to make corresponding changes in the script shown here.