LogPath in config.psd1 from env var

Hello
I modified \Config\config.psd1 LogPath (MSI and Toolkit) to use an environment variable that points to our logfile folder. The environment variable is available on every client.

Log path used for MSI logging.
LogPath = “$env:PkgLogPath”

When I run invoke-appdeploytoolkit.ps1 with this configuration it shows the following error:

A variable that cannot be referenced in restricted language mode or a data section is being referenced…

How should the config.psd1 be edited in order to support the usage of environment variables?

I ran into that EXACT issue.
It seems the config.psd1 file cannot handle Environment variables.
I created a PowerShell variable from the Environment variable before the session opens and reads the Config.psd1 file. (e.g. $envPkgLogPath = $env:PkgLogPath )
Then used that $envPkgLogPath PowerShell variable in the Config.psd1 file

Please note this is a PowerShell issue, not a PSADT issue.

Not sure if there is a better way.

Perhaps most counter-intuitively, put your variable into single quotes ('$env:WinDir'). We expand it ourselves for you.

PS D:\Repos\PSAppDeployToolkit\src> $ExecutionContext.InvokeCommand.ExpandString('$env:WinDir')
C:\WINDOWS

That’s the thing.

I have %LOGS% at my work.
I can’t use LogPath = '$env:Logs' in config.psd1.
PSADT v4.06 does not expand it.

So I use LogPath = '$envLogs' in config.psd1 and define the $envLogs variable before the session is opened.
That way, PSADT knows what $EnvLogs is when it reads config.psd1 when the session is opened.

Hmmmm, I thought it would? I’ll have to do some testing.

Putting the variable into single quotes was the solution in my case.

LogPath = ‘$env:PkgLogPath’

Yay! Thanks for confirming :sign_of_the_horns: