# How to access access a path in \\AppData\\Local without a variable ?

**URL:** <https://forums.powershell.org/t/how-to-access-access-a-path-in-appdata-local-without-a-variable/15557>\
**Category:** PowerShell Help\
**Created:** [January 30, 2021, 4:57am UTC](https://forums.powershell.org/t/how-to-access-access-a-path-in-appdata-local-without-a-variable/15557 "2021-01-30T04:57:31Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![ancient](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@ancient](https://forums.powershell.org/u/ancient)\
**Post date:** [January 30, 2021, 4:57am UTC](https://forums.powershell.org/t/how-to-access-access-a-path-in-appdata-local-without-a-variable/15557/1 "2021-01-30T04:57:31Z")

</div>

Hi All

Can anyone please tell me how to access/ write to the below path without using an environmental variable ?

C:\Users\logged in user\AppData\Local

The reason for this is it will be deployed via a scheduled task…and doing it that way does not allow the environmental variables…ie script runs but doesn’t make any changes, weird I know !

Many thanks for any info.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 30, 2021, 5:19am UTC](https://forums.powershell.org/t/how-to-access-access-a-path-in-appdata-local-without-a-variable/15557/2 "2021-01-30T05:19:59Z")

</div>

If it’s about getting the currently logged on user from a system account session you could query the registry.

```
$User = 
Get-Childitem -Path Registry::HKEY_USERS\ -ea 0 -exclude ".default"|
ForEach-Object {Get-ChildItem Registry::$_}|
Where-Object {$_.Name -like "*Volatile Environment"} | 
Get-ItemProperty -Name username
```

**$User.Username** would be the variable you can insert in your path then.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 30, 2021, 5:23am UTC](https://forums.powershell.org/t/how-to-access-access-a-path-in-appdata-local-without-a-variable/15557/3 "2021-01-30T05:23:43Z")

</div>

…

---

<div class="post-metadata">

**Author:** ![ancient](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@ancient](https://forums.powershell.org/u/ancient)\
**Post date:** [January 30, 2021, 6:45am UTC](https://forums.powershell.org/t/how-to-access-access-a-path-in-appdata-local-without-a-variable/15557/4 "2021-01-30T06:45:02Z")

</div>

Hi Olaf  
Thanks for the info…how would that work if I needed to write to that path then?

```
Get-Content $User.Username + "\AppData\Local\Microsoft\

The above does not work?
Is there any other easier method?

I am also aware of one way:

$username = (Gwmi -Class Win32_ComputerSystem).username
$path = "C:\users\" + $username + "\AppData\Local\Microsoft\
```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 30, 2021, 9:28am UTC](https://forums.powershell.org/t/how-to-access-access-a-path-in-appdata-local-without-a-variable/15557/5 "2021-01-30T09:28:53Z")

</div>

> [@](#):
>
> …how would that work if I needed to write to that path then?

Did you actually read my answer?

> [@](#):
>
> C:\Users\logged in user\AppData\Local

> [@](#):
>
> **$User.Username** would be the variable you can **insert** in your path then.

&nbsp;

---

<div class="post-metadata">

**Author:** ![ancient](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@ancient](https://forums.powershell.org/u/ancient)\
**Post date:** [January 30, 2021, 10:15am UTC](https://forums.powershell.org/t/how-to-access-access-a-path-in-appdata-local-without-a-variable/15557/6 "2021-01-30T10:15:46Z")

</div>

I did yes…but I think you misunderstood…it’s not just the username I wanted.

It was the path to the current user local appdata.

&nbsp;

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 30, 2021, 10:37am UTC](https://forums.powershell.org/t/how-to-access-access-a-path-in-appdata-local-without-a-variable/15557/7 "2021-01-30T10:37:02Z")

</div>

OK, and what’s the only part of the path what differs from user to user? 😉 … if you still don’t know what I mean I recommend to play a little bit with it and to test a few things until you get what you want.

---

<div class="post-metadata">

**Author:** ![ancient](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@ancient](https://forums.powershell.org/u/ancient)\
**Post date:** [January 30, 2021, 11:03am UTC](https://forums.powershell.org/t/how-to-access-access-a-path-in-appdata-local-without-a-variable/15557/9 "2021-01-30T11:03:50Z")

</div>

Got it thank you.

---

<div class="post-metadata">

**Author:** ![tonyd](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tonyd/32/1041_2.png) [@tonyd](https://forums.powershell.org/u/tonyd)\
**Post date:** [February 1, 2021, 7:18am UTC](https://forums.powershell.org/t/how-to-access-access-a-path-in-appdata-local-without-a-variable/15557/10 "2021-02-01T07:18:40Z")

</div>

You dont give any details on what your script is actually doing, however you do mention:

“The reason for this is it will be deployed via a scheduled task…and doing it that way does not allow the environmental variables”

What user is the script running as? If it is the current user, these should work:

`$ENV:AppData`

`$ENV:LocalAppData`

&nbsp;

---

<div class="post-metadata">

**Author:** ![ancient](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@ancient](https://forums.powershell.org/u/ancient)\
**Post date:** [February 1, 2021, 12:07pm UTC](https://forums.powershell.org/t/how-to-access-access-a-path-in-appdata-local-without-a-variable/15557/11 "2021-02-01T12:07:05Z")

</div>

[quote quote=289660]You dont give any details on what your script is actually doing, however you do mention:

“The reason for this is it will be deployed via a scheduled task…and doing it that way does not allow the environmental variables”

What user is the script running as? If it is the current user, these should work:

$ENV:AppData

$ENV:LocalAppData

[/quote]  
The issue was due to the fact it was running as system…once I changed to user…it does indeed work with variables…that then caused another issue where the powershell window would show for a brief time…even with --WindowStyle _Hidden_

But sorted that by making a vbs call the powershell.

Thanks guys.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [February 1, 2021, 1:34pm UTC](https://forums.powershell.org/t/how-to-access-access-a-path-in-appdata-local-without-a-variable/15557/12 "2021-02-01T13:34:46Z")

</div>

You can query the **USERNAME** of the currently logged on user even from inside a system session with the code I posted in my first answer. And when you insert this **USERNAME** in a path like this : "C:\</span\>users\<strong\>USERNAME\</span\>AppData\</span\>Local\</span\>Microsoft" you’ve got what you need. Is it really that hard to understand?

---

<div class="post-metadata">

**Author:** ![ancient](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@ancient](https://forums.powershell.org/u/ancient)\
**Post date:** [February 2, 2021, 10:45pm UTC](https://forums.powershell.org/t/how-to-access-access-a-path-in-appdata-local-without-a-variable/15557/14 "2021-02-02T22:45:45Z")

</div>

Olaf…I did confirm I understood and already thanked you for the info above ? comment no 289312

The issue is resolved…

Cheers and Many thanks

---

<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, 8:27pm UTC](https://forums.powershell.org/t/how-to-access-access-a-path-in-appdata-local-without-a-variable/15557/15 "2024-05-16T20:27:55Z")

</div>


