Public/Get-emsIsEnvironmentLocal.ps1
<#PSScriptInfo
.VERSION 1.0.0 .GUID 09b93363-cdfa-4b08-9efc-31472000a363 .AUTHOR enthus Managed Services GmbH .COMPANYNAME enthus Managed Services GmbH #> #Requires -Version 5.1 <# .SYNOPSIS Checks and returns whether the environment is 'local'. .DESCRIPTION Checks and returns whether the environment is 'local'. Takes environment variable '$PSPrivateMetadata.JobId' and checks its content. If this variable has content, the environment is not 'local'. .NOTES PSVersion: 5.1.x or 7.2.x ENVIRONMENT: [x] Azure Automation [ ] Azure Function [x] Local [ ] Nerdio [ ] PowerShell Universal [ ] Server [ ] ... REQUIRED CONTEXT: [ ] Application && Delegated [x] Application [x] Delegated [x] User REQUIRED PERMISSIONS: - None .INPUTS None. .OUTPUTS System.Boolean. Returns a boolean value with the information if the environment is 'local'. .EXAMPLE $isEnvironmentLocal = Get-emsIsEnvironmentLocal Validates if script is running in local environment ($true) or Azure Runbook ($false). #> function Get-emsIsEnvironmentLocal { [CmdletBinding()] param () $verbosePrefix = "Get-emsIsEnvironmentLocal | " Write-Verbose "$($verbosePrefix)Get active environment ..." if ($PSPrivateMetadata.JobId) { Write-Verbose "$($verbosePrefix)Environment: Azure Runbook" return $false } else { Write-Verbose "$($verbosePrefix)Environment: Local" return $true } } |