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

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.

I don’t think this question is relevant to PowerShellProTools but I will respond it anyway.

As you are deploying a scheduled task I assume it is running under Local System account. The logged in user is the one running process explorer.exe therefore the way to find it is using any of the two commands below. I recommend you to trying both and see what results you obtain.

$currentUser = (Get-WmiObject -Class Win32_Process -Filter ‘Name=“explorer.exe”’).GetOwner().User

  • or -

$currentUser = (Get-Process -IncludeUserName explorer | % username | sort Username -Unique).split(’\’)[1]

Once you have the current user replace it in C:\Users\$currentUser\AppData\Local

Thank you all for your supportive reply.