Public/Get-PstAutomationMode.ps1
function Get-PstAutomationMode { <# .SYNOPSIS Gets the current automation mode status for PowerShell Template functions. .DESCRIPTION Returns the current automation mode status, including whether it's explicitly set or automatically detected based on the environment (CI/CD, non-interactive, etc.). .PARAMETER Detailed Returns detailed information about automation mode detection. .EXAMPLE Get-PstAutomationMode Returns $true if automation mode is enabled, $false otherwise. .EXAMPLE Get-PstAutomationMode -Detailed Returns an object with detailed automation mode information. .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 Set-PstAutomationMode #> [CmdletBinding()] param ( [Parameter(Mandatory = $false)] [switch]$Detailed ) begin { Write-Debug -Message "Begin '$($MyInvocation.MyCommand.Name)' at '$(Get-Date)'" } process { try { $automationStatus = Test-AutomationMode if ($Detailed) { $detectionReasons = @() if ($script:PstAutomationMode -eq $true) { $detectionReasons += "Explicitly enabled via Set-PstAutomationMode" } if ($env:CI -eq 'true') { $detectionReasons += "CI environment detected (CI=true)" } if ($env:GITHUB_ACTIONS -eq 'true') { $detectionReasons += "GitHub Actions environment detected" } if ($Host.Name -eq 'ServerRemoteHost') { $detectionReasons += "Remote PowerShell session detected" } if (-not [Environment]::UserInteractive) { $detectionReasons += "Non-interactive environment detected" } return [PSCustomObject]@{ AutomationMode = $automationStatus ExplicitlySet = ($script:PstAutomationMode -eq $true) DetectionReasons = $detectionReasons Environment = @{ CI = $env:CI GitHubActions = $env:GITHUB_ACTIONS HostName = $Host.Name UserInteractive = [Environment]::UserInteractive } } } else { return $automationStatus } } catch { Write-Error "Failed to get automation mode status: $($_.Exception.Message)" return $false } } end { Write-Debug -Message "End '$($MyInvocation.MyCommand.Name)' at '$(Get-Date)'" } } |