Get Local Administrators
Summary
This task lists the local administrators on windows machine and stores the result in a custom field Local Admins List.
Sample Run


Dependencies
Task Creation
Script Details
Step 1
Navigate to Automation ➞ Tasks

Step 2
Create a new Script Editor style task by choosing the Script Editor option from the Add dropdown menu
The New Script page will appear on clicking the Script Editor button:

Step 3
Fill in the following details in the Description section:
- Name:
Get Local Administrators - Description:
This script lists the local administrators on windows machine and stores the result in a custom field "Local Admins List". - Category:
Custom

Script Editor
Click the Add Row button in the Script Editor section to start creating the script
A blank function will appear:
Row 1 Function: PowerShell script
- Use Generative AI Assist for script creation:
False - Expected time of script execution in seconds:
900 - Operating System:
Windows - Continue on Failure:
True - PowerShell Script Editor:
try {
$AllUsers = net localgroup administrators 2>&1
if ($LASTEXITCODE -ne 0) {
throw "Result: Failed to execute 'net localgroup administrators'. Output: $AllUsers"
}
$users = $AllUsers |
Where-Object {
$_ -and
$_ -notmatch 'command completed|---|Alias name|Members|comment'
} |
ForEach-Object { $_.Trim() }
if (-not $users -or $users.Count -eq 0) {
write-output "Result: No local administrator accounts were found."
exit 0
}
$users -join '|'
}
catch {
Write-Error "Result: Error fetching local administrators: $($_.Exception.Message)"
throw
}

Row 2 Function: Script Log
- Script Log Message:
%Output% - Continue on Failure:
False - Operating System:
Windows
Step 3 Logic: If/Then
Click on Add Logic > select If/Then
Row 3a Condition: Output Contains
- Condition:
Output - Operator:
Does not Contain - Input Values:
Result
Row 3b Function: Set Custom Field
- Select
Local Admins Listfrom dropdown - Add
%output%in the Value
Save Task
Click the Save button at the top-right corner of the screen to save the script.
Completed Task

Output
- Script Log
Schedule Task
Task Details
- Name:
Get Local Administrators - Description:
This script lists the local administrators on windows machine and stores the result in a custom field "Local Admins List". - Category:
Custom
Schedule
- Schedule Type:
Schedule - Timezone:
Local Machine Time - Start:
<Current Date> - Trigger:
TimeAt<Current Time> - Recurrence:
Every day

Targeted Resource
Device Group: Machines Opted for Local Admin Detection
Completed Scheduled Task
