Update-GSUser cannot be run in non-interactive mode
ShamanStarsha opened this issue · 1 comments
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:
- Ran from within Jenkins:
- Update-GSUser -user username@domain.com -RecoveryEmail recovery@otherdomain.com
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
+ Update-GSUser -user $newuser -RecoveryEmail $username.Use ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Update-GSUser
Environment (please complete the following information):
- OS: Server 2019 1809
- PowerShell Version: Windows PowerShell 5.1
- PSGSuite Version: 2.36.4
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
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!