question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Introduce new preference variable '$ForcePreference' similar to '$ConfirmPreference'

See original GitHub issue

Summary of the new feature/enhancement

In a nutshell, there is no way to generally -Force all cmdlets to suppress prompts.

image

This requires to add -Force to every cmdlet:

My-CmdletWithConfirmation –Force

While for -Confirm someone could set the $ConfirmPreference, there is no such variable for -Force. See also use -confirm instead of “-force” and Everything you wanted to know about ShouldProcess.

Proposed technical implementation details (optional)

Introduce a preference variable $ForcePreference similar to $ConfirmPreference.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
fawohlsccommented, Jan 7, 2021

Thank you @mklement0 - very helpful! 🥇

1reaction
mklement0commented, Jan 7, 2021

Glad to hear it, @fawohlsc. Don’t know if it’s required in your case, but I forgot to mention that you should run $PSDefaultParameterValues = $PSDefaultParameterValues.Clone() first, to create a local copy of the dictionary; without that, $PSDefaultParameterValues['*:Force'] - even when run in a non-global scope - takes effect globally. I’ve updated my previous comment accordingly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

about Preference Variables - PowerShell
The preference variables affect the PowerShell operating environment and all commands run in the environment.
Read more >
ConfirmPreference - PowerShell Team
Stop-Process is defined as “MEDIUM”. You can then set the variable: $ConfirmPreference to be the level that you want Automatic confirmation ...
Read more >
Powershell Preference Variables
The $PSDefaultParameterValues preference variable lets you specify custom default values for just one specific cmdlet or advanced function, see Help about_ ...
Read more >
PowerShell: the preference variable $confirmPreference
Now, if the value of the preference variable $confirmPreference is lower than that of a command, the command requires the user to confirm...
Read more >
c# - How do I set $ConfirmPreference = "None" for a ...
While the accepted answer solved this specific problem, the correct way of setting $ConfirmImpact preference variable is via session state:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found