$Env:HOMEDRIVE in DSC

I recently made the switch to creating Class-based PowerShell DSC resources. In this, I discovered that each time I use $env:HOMEDRIVE it returns a null value. I tried enclosing it with ‘$()’ but that didn’t help.

 

Is there a way to use Environment Variables in the code that I’m missing?

 

Thanks in advance,

Russ

DSC resources by LCM runs with system account by default. You will have to run as a specific user to use this environment variable.

Below links will help.

https://docs.microsoft.com/en-us/powershell/dsc/configurations/runasuser
https://www.powershellmagazine.com/2014/08/13/running-commands-as-another-user-using-dsc-script-resource/

Thanks kvprasoon. That makes perfect sense.