diff --git a/PowerShell/post_notices.ps1 b/PowerShell/post_notices.ps1 index d9b2478..505e890 100644 --- a/PowerShell/post_notices.ps1 +++ b/PowerShell/post_notices.ps1 @@ -18,12 +18,23 @@ param( # Defaults to a .env file next to the repo root (one level up from this script), # matching where the Python version expects it. - [string]$EnvFile = (Join-Path $PSScriptRoot "..\.env") + [string]$EnvFile ) $ErrorActionPreference = "Stop" -. (Join-Path $PSScriptRoot "PolarisClient.ps1") +# $PSScriptRoot isn't always populated (e.g. PowerShell 2.0, or the script being +# dot-sourced/pasted rather than run via -File), so fall back to $MyInvocation. +$ScriptRoot = $PSScriptRoot +if (-not $ScriptRoot) { + $ScriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path +} + +if (-not $EnvFile) { + $EnvFile = Join-Path $ScriptRoot "..\.env" +} + +. (Join-Path $ScriptRoot "PolarisClient.ps1") function Import-DotEnv { param([string]$Path)