rmbolger / Posh-ACME

PowerShell module and ACME client to create certificates from Let's Encrypt (or other ACME CA)
https://poshac.me/docs/latest/
MIT License
778 stars 190 forks source link

Expand environment variables in `POSHACME_HOME` #497

Closed jantari closed 1 year ago

jantari commented 1 year ago

Reading the docs here: https://poshac.me/docs/v4/Guides/Using-an-Alternate-Config-Location/#why-bother

  • Windows: %LOCALAPPDATA%\Posh-ACME

I understood it that I could use environment variables such as %LOCALAPPDATA% inside the POSHACME_HOME path. This would be expected as Windows itself also supports these variables inside %PATH% paths. So I set my POSHACME_HOME to %ProgramData%\Posh-ACME.

But when I ran Posh-ACME after this change I got this warning (and then a bunch of erros):

WARNING: The POSHACME_HOME environment variable exists but the path it points to, %ProgramData%\Posh-ACME, does not. Using default config location.


imo Posh-ACME should call [Environment]::ExpandEnvironmentVariables() on the path it finds inside POSHACME_HOME so that these Windows-style environment variables are expanded and supported. Maybe someone wants to configure a different but still dynamic/per-user POSHACME_HOME such as a path inside %AppData% or %USERPROFILE% or just in another directory inside %LOCALAPPDATA% these additional usecases would also be enabled by this.

Currently I have hardcoded the path as a temporary workaround but this is very suboptimal as the path of %ProgramData% is not always C:\ProgramData on all systems.

Thanks!

rmbolger commented 1 year ago

Hey @jantari, thanks for reaching out. This is an excellent suggestion! I'll get the change in and it should be live in the next release. It will also work on non-Windows hosts as well, though it appears you still have to use the Windows style %NAME% for it to work rather than $NAME.

rmbolger commented 1 year ago

This is now live in 4.18.0