I have a script that needs to run from Software Center when a non-admin is logged in.
It needs to copy application data to $ENV:USERNAME\AppData\<dir>\* (among other things) and it needs to run as administrator to work properly.
The problem that I've discovered is that when the script is run on a non-admin profile with admin privileges the environment variable $ENV:USERNAME returns the machine name rather than the actual logged in username.
Is there a way around this?
You can either use
([Security.Principal.WindowsIdentity]::GetCurrent()).Nameor you get the profile path from the registry :Choose your weapon :)