We have a client with a new RDS server and they want their all of their staff to have the “CutePDF Writer” as their default printer, but only when on that computer. To that end we wrote this script:
NOTE: Change the YOUR COMPUTER NAME HERE to the name of the server/computer you want this applied to.
# Check if the script is running on the target server
if ($env:COMPUTERNAME -ceq "YOUR COMPUTER NAME HERE") {
try {
# Get the WMI object for Win32_Printer
$Printer = Get-WmiObject -Class Win32_Printer | Where-Object {$_.Name -eq "CutePDF Writer"}
if ($Printer) {
# Set the default printer and discard the output
$null = $Printer.SetDefaultPrinter()
Write-Host "Successfully set 'CutePDF Writer' as the default printer."
} else {
Write-Warning "Printer 'CutePDF Writer' not found on this server."
}
} catch {
Write-Error "An error occurred: $_"
}
}
GPO to Apply To Your Users
- Open Group Policy Management Console (GPMC): On a domain controller or a machine with the Remote Server Administration Tools (RSAT) installed, open
gpmc.msc
- Create a New GPO or Edit an Existing One:
- Best Practice: Create a new Group Policy Object (GPO) specifically for this purpose. This keeps things organized. Right-click on your domain or an appropriate organizational unit (OU) containing the RDS server and select “Create a GPO in this domain, and Link it here…”. Name it something descriptive like “Set CutePDF as Default on RDS Server”
- Alternatively, you can edit an existing GPO that is already linked to the OU containing your RDS server, but be cautious about the scope of the GPO
- Edit the GPO: Right-click on the newly created (or selected) GPO and choose “Edit…”
- Navigate to User Configuration: In the Group Policy Management Editor, navigate to:
User Configuration > Policies > Windows Settings > Scripts (Logon/Logoff)
- Configure the Logon Script:
- Double-click on “Logon” in the right-hand pane
- Click the “Add…” button
- In the “Script Name” field, click “Browse…” and navigate to the location where you saved your PowerShell script (e.g., a shared network folder that the RDS server can access). Select the
.ps1
file - You can leave the “Script Parameters” field blank
- Click “OK” twice to close the dialog boxes
- Link the GPO to the RDS Server OU: Ensure that the GPO you created or edited is linked to the Organizational Unit (OU) that contains your RDS server object. Do not link this GPO to OUs containing user accounts directly. The script itself handles the condition of running only on the specific server
0 Comments