# $Env:HOMEDRIVE in DSC

**URL:** <https://forums.powershell.org/t/env-homedrive-in-dsc/12102>\
**Category:** DSC\
**Created:** [February 28, 2019, 10:04am UTC](https://forums.powershell.org/t/env-homedrive-in-dsc/12102 "2019-02-28T10:04:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![russell](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@russell](https://forums.powershell.org/u/russell)\
**Post date:** [February 28, 2019, 10:04am UTC](https://forums.powershell.org/t/env-homedrive-in-dsc/12102/1 "2019-02-28T10:04:07Z")

</div>

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.

&nbsp;

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

&nbsp;

Thanks in advance,

Russ

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [February 28, 2019, 1:30pm UTC](https://forums.powershell.org/t/env-homedrive-in-dsc/12102/2 "2019-02-28T13:30:54Z")

</div>

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.

> **[Use Credentials with DSC Resources - PowerShell](https://docs.microsoft.com/en-us/powershell/dsc/configurations/runasuser?view=dsc-1.1)**
>
> DSC allows you to provide credentials to a configuration so that configuration settings can be applied the in the context of a specific user account rather than the Local System account.

> **[Running commands as another user using DSC script resource](https://powershellmagazine.com/2014/08/13/running-commands-as-another-user-using-dsc-script-resource/)**
>
> A while ago, I received an email from a reader who wanted to run a few Exchange PowerShell cmdlets using DSC.

---

<div class="post-metadata">

**Author:** ![russell](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@russell](https://forums.powershell.org/u/russell)\
**Post date:** [February 28, 2019, 9:15pm UTC](https://forums.powershell.org/t/env-homedrive-in-dsc/12102/3 "2019-02-28T21:15:25Z")

</div>

Thanks kvprasoon. That makes perfect sense.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 9:16pm UTC](https://forums.powershell.org/t/env-homedrive-in-dsc/12102/4 "2024-05-16T21:16:22Z")

</div>


