Public/Set-PstAutomationMode.ps1
function Set-PstAutomationMode { <# .SYNOPSIS Sets the automation mode for PowerShell Template functions. .DESCRIPTION When automation mode is enabled, PowerShell Template functions will not prompt for user confirmation and will bypass interactive prompts. This is useful for CI/CD pipelines, automated scripts, and non-interactive environments. .PARAMETER Enabled (Required) Boolean value to enable ($true) or disable ($false) automation mode. .PARAMETER PassThru Returns the current automation mode state after setting it. .EXAMPLE Set-PstAutomationMode -Enabled $true Enables automation mode for all PST functions. .EXAMPLE Set-PstAutomationMode -Enabled $false -PassThru Disables automation mode and returns the current state. .NOTES Automation mode is automatically detected in CI/CD environments: - GitHub Actions (GITHUB_ACTIONS=true) - General CI environments (CI=true) - Non-interactive PowerShell hosts - Remote PowerShell sessions .LINK Get-PstAutomationMode #> [CmdletBinding(SupportsShouldProcess)] param ( [Parameter(Mandatory = $true, Position = 0)] [bool]$Enabled, [Parameter(Mandatory = $false)] [switch]$PassThru ) begin { Write-Debug -Message "Begin '$($MyInvocation.MyCommand.Name)' at '$(Get-Date)'" } process { try { if ($PSCmdlet.ShouldProcess("Global automation mode", "Set to $Enabled")) { $script:PstAutomationMode = $Enabled if ($Enabled) { Write-Verbose "PowerShell Template automation mode ENABLED - functions will not prompt for confirmation" } else { Write-Verbose "PowerShell Template automation mode DISABLED - functions will prompt for confirmation when needed" } if ($PassThru) { return $script:PstAutomationMode } } } catch { Write-Error "Failed to set automation mode: $($_.Exception.Message)" } } end { Write-Debug -Message "End '$($MyInvocation.MyCommand.Name)' at '$(Get-Date)'" } } |