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 !
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\
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.
[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.
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?