diff --git a/encrypt-key.ps1 b/encrypt-key.ps1 index 9d7da09..4e3339b 100644 --- a/encrypt-key.ps1 +++ b/encrypt-key.ps1 @@ -2,11 +2,23 @@ [CmdletBinding()] param( [switch]$UpdateConfig, - [string]$ConfigPath = (Join-Path $PSScriptRoot 'appsettings.Development.json') + [string]$ConfigPath ) $ErrorActionPreference = 'Stop' +if ([string]::IsNullOrWhiteSpace($ConfigPath)) { + $scriptDirectory = $PSScriptRoot + if ([string]::IsNullOrWhiteSpace($scriptDirectory) -and + -not [string]::IsNullOrWhiteSpace($MyInvocation.MyCommand.Path)) { + $scriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Path + } + if ([string]::IsNullOrWhiteSpace($scriptDirectory)) { + throw 'Cannot determine the script directory. Specify -ConfigPath with the full config path.' + } + $ConfigPath = Join-Path $scriptDirectory 'appsettings.Development.json' +} + function ConvertTo-EncryptedValue { param( [Security.SecureString]$Value,