In this article, we will use a PowerShell (.ps1) script to get the value for a custom field and use it to install Sophos Antivirus on a machine.
Notes:
- You would need to install the PSAtera module in Powershell before using this script.
- You can adjust the script to your requirements by changing the values of the variables in the first three lines of the script.
1. Copy the below script.
$AteraAPIKey = 'MY ATERA API KEY' $FieldName = 'Sophos Key' $SophosURI = 'https://SOME SHAREPOINT PUBLIC URL FOR/SophosSetup.exe' # Install and load the right version of Atera if (!(Get-Module -ListAvailable PSAtera)) { Install-Module -Name PSAtera -MinimumVersion 1.3.1 -Force } Import-Module -Name PSAtera -MinimumVersion 1.3.1 Set-AteraAPIKey -APIKey $AteraAPIKey # Get the agent information for the PC that's running the script $agent = Get-AteraAgent # Get the value from the Customer endpoint $customValue = Get-AteraCustomValue -ObjectType Customer -ObjectId $agent.CustomerID -FieldName $FieldName # Download Sophos Installer to temp path $SophosInstaller = Join-Path -Path $env:TEMP -ChildPath "SophosSetup.exe" Invoke-WebRequest -Uri $SophosURI -OutFile $SophosInstaller & $SophosInstaller --customertoken="$($customValue.ValueAsString)" --epiinstallerserver="api-cloudstation-us-east-2.prod.hydra.sophos.com" --products="all" --quiet # Get the status of the Sophos Install do { Get-Process -Name "*SophosSetup.exe*" Start-Sleep -Seconds 10 } while (Get-Process -Name "*SophosSetup.exe*" -ErrorAction SilentlyContinue) # After install is over, get the status of the Sophos Services Get-Service -Name "*Sophos*"
2. Make any required changes to the first 3 variables of the script.
3. Run the script on the desired machine.
You can add the Script in Atera and execute it through an IT Automaton profile.
NOTE: The script was not screened for functionality and we do not offer troubleshooting support for it. Please review and test it in your lab environment first.
Thank you, Dave Long, for creating this script and for your contribution to the Atera community!