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
- 42 Getting started
- 26 Read before posting
- 8 Meet and greet
- 257 General
- 71 News and announcements
- 2 Swag
- 1 Roadmap updates
- 83 Resources
- 12 Knowledge Base
- 17 Webinars
- 1 Shared Script Library
- 2 Blog
- 21 Pro Tips
- 28 Got an idea?
- 3 Atera Academy
- 2 ActionAI
- 1 Copilot
- 142 Remote Monitoring and Management
- 85 Remote Monitoring
- 28 Patch Management
- 107 Professional Services Automation
- 65 Helpdesk
- 17 Billing
- 22 Reporting
- 41 Integrations & add-ons
- 22 Integrations
- 11 Add-ons
- 108 Scripting and automations
- 62 Scripts
- 32 Automations