Powershell not running as logged on user
I have a package to deploy Arduino IDE. One of the steps requires editing the preferences.txt file in the logged on users %localappdata% folder, but this step is failing and the output shows this is due to the file not being found, because, I believe, it is not being run as the logged on user.
Here is the step Details
(Get-Content %localappdata%\Arduino15\preferences.txt) | ForEach-Object { $_ -replace "update.check=true" , "update.check=false" } | Set-Content %localappdata%\Arduino15\preferences.txt
with Actions > Run As > 'logged on user'
with Conditions > Logged on State > 'Only run when a user is logged in'
The output shows
Get-Content : Cannot find path
'C:\WINDOWS\AdminArsenal\PDQDeployRunner\service-1\exec\%localappdata%\Arduino15\preferences.txt' because it does not
exist.
At C:\WINDOWS\AdminArsenal\PDQDeployRunner\service-1\exec\user.ps1:1 char:2
+ (Get-Content %localappdata%\Arduino15\preferences.txt) | ForEach-Obje ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\WINDOWS\Admi...preferences.txt:String) [Get-Content], ItemNotFoundEx
ception
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
What am I doing wrong?
0
Comments
Try. I think you're using a File Explorer variable instead of the PowerShell environment variable.
I ran your command in a PowerShell on my PC and noticed that it's adding "%localappdata%\Arduino15\preferences.txt" to the current path that the session is running in. So it wasn't handling the variable correctly. In your error above, you can see the same thing. It's adding your target path to the directory where the deploy service is running from.
Bingo! This worked perfectly. My mistake for not spotting a CMD variable wouldn't be compatible with Powershell. Many thanks!