Using Environment Variables in PowerShell Scripts
hey guys, how's everyone doing?
I'm exploring possibilities with scripts in atera and would like recommendations for working with environment variables.
In my tests I noticed that the script submission occurs through a powershell session with different values than the real user.
Values like $env:USERNAME may not exactly match the actual user of the machine.
My context of use is to subscribe to TeamViewer groups for example, cost to subscribe to the devices by getting the user/device name.
Exemple: My real value when I run whoami is AzureAD\MarcosSantos
'''
$userlocal = whoami
Write-Host $userlocal
'''
Comments
-
Hi,
That's because the Atera service runs at NT AUTH\SYSTEM, if you ran your script as current user it would use your AzureAD or whatever that user that's logged in as, if nobody is logged in it would say "No user logged in" and won't run the script.
1 -
Thank you Alex, the option is in my face all the time. Making the change worked well.
Before reading your answer I got a positive result with the following command:
Get-WmiObject -Class Win32_ComputerSystem | Select-Object -ExpandProperty UserName
Just documenting the discovery, thank you for the support.
0
Topics
- All Topics
- 40 Getting started
- 24 Read before posting
- 8 Meet and greet
- 232 General
- 63 News and announcements
- 1 Swag
- 1 Roadmap updates
- 75 Resources
- 12 Knowledge Base
- 14 Webinars
- 1 Shared Script Library
- 2 Blog
- 18 Pro Tips
- 26 Got an idea?
- 3 Atera Academy
- 2 ActionAI
- 1 Copilot
- 132 Remote Monitoring and Management
- 82 Remote Monitoring
- 25 Patch Management
- 103 Professional Services Automation
- 64 Helpdesk
- 17 Billing
- 19 Reporting
- 35 Integrations & add-ons
- 20 Integrations
- 10 Add-ons
- 102 Scripting and automations
- 61 Scripts
- 29 Automations