---
title: How to Monitor a Clustered Windows Service with Nodinite and PowerShell
description: Monitor and automate clustered Windows services with Nodinite. Achieve high availability, automate self-healing, and empower users with secure PowerShell-based monitoring and remote actions.
---

# :fa-server: How to Monitor a Clustered Windows Service with Nodinite and PowerShell  
  
Take control of your clustered Windows services with :Nodinite:. This guide shows you how to monitor, automate, and empower users using custom [PowerShell][] scripts for high availability and self-healing.  
  
* ✅ Achieve high availability and rapid issue detection for clustered services  
* ✅ Automate self-healing and remediation with custom PowerShell scripts  
* ✅ Empower users with secure remote actions and self-service monitoring  
* ✅ Centralize management and compliance for all monitored services  

---
  
## Why Monitor Clustered Windows Services with Nodinite?  
  
:Nodinite: [Windows Server Monitoring Agent][] lets you monitor any Windows service—including those running in clustered environments. By leveraging custom PowerShell scripts, you can automate health checks, detect failures, and trigger remediation actions, all from a single, unified platform.  
  
**Key benefits:**  

* Monitor service state across all cluster nodes for true high availability  
* Automate failover and recovery using PowerShell-based remote actions  
* Provide secure, role-based access for self-service troubleshooting  
* Integrate with :Nodinite: [Monitor Views][] for centralized visibility and alerting  
  
---

<div class="mermaid">
graph TD
    subgraph "Nodinite Platform"
        monitor[fa:fa-server Nodinite Monitoring Agent]
    end
    subgraph "Windows Cluster"
        node1[fa:fa-server Cluster Node 1]
        node2[fa:fa-server Cluster Node 2]
        node3[fa:fa-server Cluster Node N]
        service[fa:fa-cogs Windows Service]
        node1 --> service
        node2 --> service
        node3 --> service
    end
    monitor --> node1
    monitor --> node2
    monitor --> node3
</div>

*Diagram: :Nodinite: [Monitoring Agent][Monitoring Agents] checks the status of a clustered Windows service across all nodes for **high availability**.*
  
## Example: PowerShell Script for Clustered Service Monitoring  
  
Below is a sample PowerShell script that checks the status of a clustered Windows service across all nodes. It reports the state to :Nodinite: and can be extended for automated remediation.  
  
```powershell
param (
    [string]$ClusterName = "YourClusterName",
    [string]$ServiceName = "YourServiceName",  # This is the *actual service name*, e.g., "MyService"
    [string]$ClusterResourceName = "YourClusterResourceName"  # The name of the clustered role/resource
)

function Write-Ok {
    Write-Output "Service '$ServiceName' is running correctly on the active cluster node."
    exit 0
}

if (-not (Get-Module -ListAvailable -Name FailoverClusters)) {
    Write-Error "Failover Clustering module is not available on this system."
    exit 1
}

try {
    Import-Module FailoverClusters -ErrorAction Stop
} catch {
    Write-Error "Could not import FailoverClusters module. $_"
    exit 1
}

try {
    $ownerNode = (Get-ClusterGroup -Cluster $ClusterName | Where-Object { $_.Name -eq $ClusterResourceName }).OwnerNode
    if (-not $ownerNode) {
        Write-Error "Could not determine owner node for clustered resource '$ClusterResourceName'."
        exit 1
    }
} catch {
    Write-Error "Error getting owner node of clustered resource. $_"
    exit 1
}

# Now check service status only on the owning node
$runningNodes = @()
$clusterNodes = Get-ClusterNode -Cluster $ClusterName

foreach ($node in $clusterNodes) {
    try {
        $session = New-PSSession -ComputerName $node.Name -ErrorAction Stop
        $service = Invoke-Command -Session $session -ScriptBlock {
            Get-Service -Name $using:ServiceName -ErrorAction Stop
        }
        Remove-PSSession -Session $session

        if ($service.Status -eq 'Running') {
            $runningNodes += $node.Name
        }
    } catch {
        Write-Warning "Could not query service '$ServiceName' on node '$($node.Name)': $_"
    }
}

switch ($runningNodes.Count) {
    1 {
        if ($runningNodes[0] -eq $ownerNode.Name) {
            Write-Ok
        } else {
            Write-Error "Service '$ServiceName' is running on node '$($runningNodes[0])' but the active cluster node is '$($ownerNode.Name)'."
        }
    }
    0 { Write-Error "Service '$ServiceName' is not running on any cluster node." }
    default { Write-Error "Service '$ServiceName' is running on multiple nodes: $($runningNodes -join ', '). This violates single-node constraint." }
}

```

*Example PowerShell script for monitoring a clustered Windows service. Extend this script to trigger automated remediation or notifications using :Nodinite: [Remote Actions][].*  
  
<div class="mermaid">
graph LR
    monitor[fa:fa-server Nodinite Monitoring Agent] --> check[fa:fa-search Health Check]
    check --> ok[fa:fa-check OK]
    check --> fail[fa:fa-times Error]
    fail --> remediate[fa:fa-bolt Self-Healing Script]
    remediate --> ok
</div>

*Diagram: Nodinite can automatically trigger self-healing PowerShell scripts if a clustered service fails health checks.*  

---
  
## How Nodinite Empowers Cluster Monitoring  
  
:Nodinite: enables you to run custom PowerShell scripts for advanced monitoring, automation, and secure self-service actions. You can:  
  
* Execute scripts for health checks, failover, and recovery  
* Empower end-users to run scripts as Remote Actions on demand  
* Centralize script management and execution for security and compliance  
* Integrate with Monitor Views for real-time state evaluation and alerting  
  
>[!NOTE]  
>Learn how to utilize your own PowerShell scripts for custom monitoring, enabling end-users to execute them through self-service enabled :Nodinite: Monitor Views.  
  
---
  
## :fa-hand-point-right: Next Steps

:fa-sliders-h: [Learn more about PowerShell monitoring][PowerShell]  
:fa-display: [Add or manage Monitor View][]  

## :fa-link-horizontal: Related Topics

* :fa-rectangle-terminal: [PowerShell Monitoring Features][PowerShell]  
* :fa-gears: [Windows Server Monitoring Agent][]  
* :fa-lightbulb-on: [Resources][]  
* :fa-cloud-arrow-down: [Monitoring][]  
* :fa-display: [Monitor Views][]  
* :fa-database: [SQL Server - SQL Statements][] - Similar custom scripting approach for database monitoring  

[Add or manage Monitor View]:{ndr}/Administration/2.%20Monitor%20Management/1.%20Monitor%20Views/Features/Add%20or%20manage%20Monitor%20View.md
[Monitor Views]:{ndr}/Administration/2.%20Monitor%20Management/1.%20Monitor%20Views/Features/What%20is%20a%20Monitor%20View.md
[Monitoring]:nodiniteDoc:/Monitoring
[Monitoring Agents]:{ndr}/Administration/2.%20Monitor%20Management/2.%20Monitor%20Agents/Features/What%20is%20a%20Monitor%20Agent.md
[PowerShell]:{ndr}/Logging%20and%20Monitoring/Windows%20Server/Features/PowerShell.md  
[Remote Actions]:{ndr}/Getting%20Started/3.%20Monitor/Remote%20Actions.md
[Resources]:{ndr}/Administration/2.%20Monitor%20Management/3.%20Resources/Features/What%20is%20a%20Resource.md  
[SQL Server - SQL Statements]:{ndr}/Logging%20and%20Monitoring/Database/Features/SQL%20Statements/SQL%20Server%20-%20Statements.md
[Windows Server Monitoring Agent]:{ndr}/Logging%20and%20Monitoring/Windows%20Server/Overview.md