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.
1
Topics
- All Topics
- 41 Getting started
- 25 Read before posting
- 8 Meet and greet
- 237 General
- 64 News and announcements
- 1 Swag
- 1 Roadmap updates
- 79 Resources
- 12 Knowledge Base
- 16 Webinars
- 1 Shared Script Library
- 2 Blog
- 19 Pro Tips
- 27 Got an idea?
- 3 Atera Academy
- 2 ActionAI
- 1 Copilot
- 140 Remote Monitoring and Management
- 84 Remote Monitoring
- 27 Patch Management
- 105 Professional Services Automation
- 64 Helpdesk
- 17 Billing
- 21 Reporting
- 36 Integrations & add-ons
- 20 Integrations
- 10 Add-ons
- 103 Scripting and automations
- 61 Scripts
- 30 Automations