Skip to the main content.

PowerShell Tips

Hiding confirmations in PowerShell

Table of contents

Post Featured Image

Tobias & Aleksandar's tip #12:

The two PowerShell experts have teamed up to share their best and most helpful PowerShell tips.

We will be publishing their scripts over the course of Scriptember in 13 blog posts. Don't miss their insights! Be sure to follow all Scriptember events, listed in our calendar here

 

Overview of all 13 articles published during Scriptember

 

 

Hiding confirmations

Occasionally, in scripts you see parameters like -Confirm:$false. This is explicitly setting a switch parameter to $false, typically in an effort to hide confirmation dialogs and enable a script to run unattended.

Any confirmation dialog that would be suppressible by this parameter can also be turned off on a script-global scope, simply by adding this to the start of the script:

  • $ConfirmPreference = 'None'


Likewise, if cmdlets show progress bars that you don’t want to see (i.e. to speed up execution time), simply turn them off:

  • $ProgressPreference = 'SilentlyContinue'


The "preference" set of variables generally enables you to tailor the PowerShell environment to your need:

  • PS C:\> Get-Variable -Name *preference

 

 

Good2know


Scriptember! Stay tuned:

During Scriptember, our calendar provides the best possible overview.  

Scriptember - hier ist die Übersicht

 

  • Follow us on social media, look for and use the hashtags #Scriptember and #PowerShell.
  • Join our live sessions, overview soon here.
  • Participate in challenges and contests. 
  • Share your knowledge.

 

Find all events here!

 

 

Related links 



Related posts

3 min read

Using enumerations in PowerShell (1/2)

Tobias & Aleksandar's tip #1:

The two very well-known PowerShell experts have teamed up to share their best and most...

5 min read

Utilizing external config data in PowerShell (1/4)

Tobias & Aleksandar's tip #3:

The two very well-known PowerShell experts have teamed up to share their best and most...

5 min read

Using enumerations in PowerShell (2/2)

Tobias & Aleksandar's tip #2:

The two very well-known PowerShell experts have teamed up to share their best and most...

About the author: