Hey abeidson,
Thanks for posting here!
I’m assuming when you mention this runs successfully on a single endpoint it means you’re running this locally correct? If so, I’m imaging the Worklet is having issues leveraging the “$env” variable in your script. When you run a script locally, it will run as the current logged-in user. However, Worklets run as SYSTEM instead and does not interact with the logged-in user.
$env:localppdata points to this path as SYSTEM:
C:\WINDOWS\system32\config\systemprofile\AppData\Local
while running it locally points here:
C:\Users\LOGGED_IN_USER\AppData\Local
I believe you’ll have to replace the $env variable with the logged in users path. You should be able to accomplish this by first getting the logged in user:
$currentUserName = (Get-CimInstance -Class Win32_ComputerSystem | Select-Object -ExpandProperty UserName) -replace '.*\\', ''
Then replace the $env as such:
C:\Users\$currentUserName\AppData\Local
This this path and see if it works for you!
Side note: If you need to test Worklets locally but run them as SYSTEM, you can download PSTools to run scripts as closely as to how they’re ran in Automox.
Please let me know if you have any questions!
Howdy Abeidson,
On top of Kyles suggestions, you may be able to get away with copying this and removing-items instead of renaming-items:
$env:localppdata points to this path as SYSTEM:
C:\WINDOWS\system32\config\systemprofile\AppData\Local
while running it locally points here:
C:\Users\LOGGED_IN_USER\AppData\Local
I believe you’ll have to replace the $env variable with the logged in users path. You should be able to accomplish this by first getting the logged in user:
$currentUserName = (Get-CimInstance -Class Win32_ComputerSystem | Select-Object -ExpandProperty UserName) -replace '.*\\', ''
Then replace the $env as such:
C:\Users\$currentUserName\AppData\Local
This this path and see if it works for you!
Thank you for this, it worked like a charm after modifying it based on the above.
Howdy Abeidson,
On top of Kyles suggestions, you may be able to get away with copying this and removing-items instead of renaming-items:
Thank you for this link. It may come in handy in the future, unfortunately due to the sprawl of the application and the other applications in AppData I couldn’t just rename folders this time around.