locked
How to suppress the prompt for confirmation int he powershell line? RRS feed

  • Question

  • Hi Experts, We are using following powershell line to remove mails which sent accidently. So it takes bulk of user input, but i am unable suppress prompt for confirm (Yesy / No) Eventhough i press "a" its not taking, for evey user i have to keep on pressing

    Import-csv "C:\SCRIPTS\EXPT.CSV" | foreach {Search-mailbox $_.alias -SearchQuery "(Subject:Planned Mainten) AND (received:27-JAN-2016)" -DeleteContent}


    Manju Gowda

    Thursday, January 28, 2016 4:12 AM

Answers

  • You should be able to suppress the prompt by providing "-force" switch. However, I'd be very careful if it's being run in production. Force will not give you a chance to interrupt the script should anything go wrong.
    Thursday, January 28, 2016 4:44 AM
  • Try adding the -Force parameter in your Search-Mailbox command. The parameters documentation says, "The Force switch overrides the confirmation prompt displayed when your use the DeleteContent switch to permanently delete messages."
    Thursday, January 28, 2016 4:45 AM

All replies

  • You should be able to suppress the prompt by providing "-force" switch. However, I'd be very careful if it's being run in production. Force will not give you a chance to interrupt the script should anything go wrong.
    Thursday, January 28, 2016 4:44 AM
  • Try adding the -Force parameter in your Search-Mailbox command. The parameters documentation says, "The Force switch overrides the confirmation prompt displayed when your use the DeleteContent switch to permanently delete messages."
    Thursday, January 28, 2016 4:45 AM
  • Wow

    Thank you both. It done the magic and it induced my Script learning hunger as well

    Appriciate both


    Manju Gowda

    Thursday, January 28, 2016 5:26 AM