Create automated response when prompted.

I'm trying to make things easier by having end users just run a script to automatically set "\\prtcen\SmartPrint" (Network printer on our domain) as the default printer. I got a script online thats similar, but it prompts me to type the printer name. I'm fairly new to powershell and I'm unsure of how I will be able to set an automatic response for the printer. please help.


[CmdletBinding(SupportsShouldProcess = $true)]

#Get the infos of all printer
$Printers = Get-WmiObject -Class Win32_Printer

If($PSCmdlet.ShouldProcess("$PrinterName","Set the default printer"))
Write-Verbose "Get the specified printer info."
$Printer = $Printers | Where{$_.Name -eq "$PrinterName"}

Write-Verbose "Setting the default printer."
$Printer.SetDefaultPrinter() | Out-Null
EHCO "\\prtcen\SmartPrint"

Write-Host "Successfully set the default printer."
Write-Warning "Cannot find the specified printer."
$ErrorMsg = $_.Exception.Message
Write-Host $ErrorMsg -BackgroundColor Red

No Data
  • Why are you doing this a user interactive script vs GPO, take the user interaction out of the picture, no coding needed?

    Just web search for --- 'gpo set default printer', and get stuff like this...

     GP Preferences: Add a new printer, set as default

     Videos of gpo set default printer

    Don't try an reinvent the wheel, unless you know it is really a better wheel, or a learning process.

    We all love PowerShell, but there are thing already built into Windows to do this sort of thing.

    PowerShell can do a tremendous amount of things, but it is not the default answer to everything, especially for one off items like what you appear to be after here.

    As for this...

    "I'm fairly new to powershell"

    ... that's all well and good. We all had to start from somewhere., but... Spend the needed time learning this stuff, to limit, avoid, bad code, misconceptions, unnecessary errors, bad habits and the like. Don't stress yourself, take advantage of all the free / no cost resources available.


    There is a MS MOC, and there are online courses.
    Yet there are many free / no cost approaches.
    Youtube (Microsoft MSDN Channel9 has a bunch of PowerShell items as well. ) - and just search ---
    'beginning powershell'
    'intermediate powershell'
    'advanced powershell'
    'PowerShell using Active Directory'
    'powershell Powergui'
    'Powershell working with files and folders'
    .. yadda, yadda.

    There are tons of free / no cost / low cost, eBooks and references.

    This question gets asked a lot on many forums and Q&A sites. Bascailly, stop using cmd.exe, and alwqays use PowerShell for everything you do, where you'd use cmd.exe and do things only using the equivalent PowerShell cmdlet. Use the help files and the help file examples to get going.

    See also posts here for other resource suggestions here:
    Learning this stuff.
    Best Practices

    Windows PowerShell Survival Guide

    Practice with PSKoans
    PSKoans : 0.50.0
    A module designed to provide a crash-course introduction to PowerShell with programming koans.

    Book references, normally the ones you'll see most recommend:

    Beginning ---
    Learn Windows PowerShell in a Month of Lunches 3rd Edition
    Donald W. Jones (Author),‎ Jeffrey Hicks (Author)
    ISBN-13: 978-1617294167
    ISBN-10: 1617294160

    Internediate ---
    Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell 3rd Edition
    Lee Holmes (Author)
    ISBN-13: 978-1449320683
    ISBN-10: 1449320686

    Advanced ---
    Windows PowerShell in Action 3rd Edition
    by Bruce Payette (Author),‎ Richard Siddaway (Author)
    ISBN-13: 978-1633430297
    ISBN-10: 1633430294

No Data