Skip to content

Instantly share code, notes, and snippets.

@codykonior
Last active April 29, 2020 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codykonior/989e7762d8d069b715f31aaa29ba3b07 to your computer and use it in GitHub Desktop.
Save codykonior/989e7762d8d069b715f31aaa29ba3b07 to your computer and use it in GitHub Desktop.
Determine whether something can accept user input or not
function Get-Interactive {
[CmdletBinding()]
param (
)
-not (
<# Jenkins and other services #>
$false -eq [Environment]::UserInteractive -or
<# Invoke-Command -ComputerName is ASSUMED to be non-interactive #>
$Host.Name -eq 'ServerRemoteHost' -or
<# RSJob, Workflow #>
$null -eq $Host.UI.SupportsVirtualTerminal -or
<# PowerShell -NonInteractive #>
[Environment]::GetCommandLineArgs() -like '-NonI*'
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment