Files
docs/scripts/Windows and Linux/Windows/Start the RMM Agent Service Across the Domain.md
T
nicole 289769a601
Automatic Documentation Deployment / Sync Docs to https://kb.bunny-lab.io (push) Successful in 8s
Restructured Documentation
2026-09-05 14:08:43 -06:00

1.8 KiB

tags
tags
PowerShell
Scripting

Purpose

Start the cagservice RMM agent service on the domain servers selected by the script. The current implementation starts that service; it does not reboot computers or restart every service.

!!! warning "Under Connstruction" This document is under construction and not generalized for general purpose use yet. Manual work needs to be done to repurpose this script for general usage.

# Clear the screen before running the script
Clear-Host
Write-Host "Starting Domain-Wide Service Restart" -ForegroundColor Green

# Main Script -------------------------------------------------------------------------------------------------------------------------

# Get a list of all servers from Active Directory
Write-Host "Retrieving server list from Active Directory..."
$servers = Get-ADComputer -Filter * -Property OperatingSystem | Where-Object {
    $_.OperatingSystem -like "*Server*"
} | Select-Object -ExpandProperty Name

# Loop through all servers and start the 'cagservice' service
foreach ($server in $servers) {
    Write-Host ("Attempting to start 'cagservice' on " + $server + "...")
    try {
        Invoke-Command -ComputerName $server -ScriptBlock {
            Start-Service -Name cagservice -ErrorAction Stop
            Write-Host "'cagservice' started successfully on $env:COMPUTERNAME"
        } -ErrorAction Stop
    } catch {
        Write-Host ("Failed to start 'cagservice' on " + $server + ": " + $_.Exception.Message) -ForegroundColor Red
    }
}

Write-Host "Script execution completed." -ForegroundColor Green