Closed ShamanStarsha closed 3 years ago
Hey @ShamanStarsha - This is default PowerShell behavior for cmdlets/functions using ShouldProcess and a ConfirmPreference set higher than the default of Medium. The Confirm
parameter is a built-in parameter for advanced functions/cmdlets when using those settings and the documentation comes from PowerShell itself. All Update-*
and Remove-*
functions in PSGSuite leverage this to prevent accidental/unexpected changes when using the module.
That being said, to disable confirmation for non-interactive scripts (or while using interactive as well), you would negate it like a typical Switch parameter by using: -Confirm:$false
. Note the colon between the parameter and boolean value, not a space. This is important for Switch parameters and will not work otherwise.
More reading: https://docs.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-shouldprocess?view=powershell-5.1
Hope this helps!
Describe the bug Attempting to run Update-GSUser in non-interactive mode fails. Update-GSUser always prompts for confirmation when running in interactive mode. Documentation suggests it should only prompt when -confirm is entered
To Reproduce Steps to reproduce the behavior:
Expected behavior Expect the command without -confirm to not prompt for confirmation.
Screenshots Update-GSUser : Exception calling "ShouldProcess" with "1" argument(s): "Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available." At C:\Windows\TEMP\jenkins6105354103505545278.ps1:115 char:13
Environment (please complete the following information):
Additional context Set line 28671 in PSGSuite.psm1 from "if ($PSCmdlet.ShouldProcess("Updating user '$U'")) {" to "if ($true) {" and I get the expected behaviour. edit: same behaviour problem with Remove-GSUser