We recently wrote brief script and article explaining how to set a specific default printer using a simple PowerShell script and Logon GPO. However, we found an even easier way to do the same thing using a simple Scheduled Task:

PowerShell Script to Set Default Printer

$DefaultPrinterName = "CutePDF Writer" # Ensure this name exactly matches the printer name

try {
    # Get the WMI object for Win32_Printer
    $Printer = Get-WmiObject -Class Win32_Printer | Where-Object {$_.Name -eq $DefaultPrinterName}

    if ($Printer) {
        # Set the default printer and discard the output
        $null = $Printer.SetDefaultPrinter()
        Write-Host "Successfully set '$DefaultPrinterName' as the default printer."
    } else {
        Write-Warning "Printer '$DefaultPrinterName' not found on this machine."
    }
} catch {
    Write-Error "An error occurred: $_"
}

Create The Scheduled Task To Run At Login

To create the new scheduled task:



Open Task Scheduler: Search for “Task Scheduler” in the Start Menu of your VM and open it. Create Basic Task: In the right-hand pane, click on “Create Basic Task…”. Name and Description:

  • Name: Give it a descriptive name like “Set Default Printer – MS Print to PDF”
  • Description: (Optional) Add a description like “Sets Microsoft Print to PDF as the default printer on user logon”
  • Click “Next”

Trigger:

  • Select “When a user logs on”
  • Delay Task For: Check the box next to “Delay task for:” and set a delay of, say, 30 seconds or 1 minute. You can experiment with this value if needed
  • Click “Next”

Action:

  • Select “Start a program”
  • Click “Next”

Program/script:

  • Enter powershell.exe

Add arguments (optional):

  • Enter -ExecutionPolicy Bypass -File "C:\Scripts\Set-MSPrintToPDF.ps1" (adjust the path if you saved the script elsewhere)
  • -ExecutionPolicy Bypass: This allows the script to run without requiring a digital signature. Since it’s a local script you’ve created, this is generally safe in this context
  • -File "C:\Scripts\Set-MSPrintToPDF.ps1": This specifies the path to your PowerShell script.  
  • Click “Next”

Finish: Review the settings and click “Finish”.



0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *