Listing NAV services on remote servers

I have customers that have multiple NAV Service Tier servers installed. Customers also want that the servers are constantly monitored and the services have to be started if they are marked to autostart whenever the server is rebooted. The PowerShell script that does the actual monitoring can also restart some services at regular basis to ensure that the memory leaks do not crash the service.

Lately, one of these customers installed a new environment with totally new servers and nav services. These servers were installed by another technician, and I was asked to install the monitoring scripts to the new environment as well.

I started the job by familiarizing myself with the environment, and quickly noticed that I need to check what services are installed into each of the servers. Since there is 4 NAV Service Tier servers for backend users and 10 front end servers for stores/LS NAV cashing terminals, I decided to create a PowerShell script to list all NAV Services and their statuses.

The script is attached here for your convenience. It requires that remote execution is enabled on each of the servers.

## This script lists NAV Services that are running or stopped in each server in the list.
## Created by Urpo Kotipalo/Solteq, 2020-09-08

Clear-Variable My*

$MyServiceName = "MicrosoftDynamicsNavServer%"

#$MyComputerList = "navprodnas01","navprodnas02"
#$MyComputerList = "navprodbo01","navprodbo02","navprodbo03","navprodbo04"
$MyComputerList = "navprodmiddle01","navprodmiddle02","navprodmiddle03","navprodmiddle04","navprodmiddle05","navprodmiddle06","navprodmiddle07","navprodmiddle08","navprodmiddle09","navprodmiddle10"

$ErrorActionPreference = 'Stop'

if ($MyComputerList) {
    Enable-PSRemoting -Force
    ForEach ($MyComputer in $MyComputerList) {
        
        #Write-Host Processing host $MyComputer
        Get-WmiObject Win32_Service -filter "Name LIKE 'MicrosoftDynamicsNavServer%' and state LIKE 'Running'" -ComputerName $MyComputer | foreach-object {
            $ServiceName = $_.Name.split('$')[1].split(',')[0]
            $MyServicesRunning = $MyServicesRunning + $ServiceName + ', '
        }
        Get-WmiObject Win32_Service -filter "Name LIKE 'MicrosoftDynamicsNavServer%' and state Like 'Stopped'" -ComputerName $MyComputer | foreach-object {
            $ServiceName = $_.Name.split('$')[1].split(',')[0]
            $MyServicesStopped = $MyServicesStopped + $ServiceName + ', '
        }
        Write-Host $MyComputer running services: $MyServicesRunning
        Write-Host $MyComputer stopped services: $MyServicesStopped
        Write-Host ---
        Clear-Variable MyServices*
    }
}

The output of the script when run in PowerShell ISE is something like below:

PS C:\Windows\system32> D:\TSTSIIRTO\GetNAVServices.ps1
navprodbo01 running services: BackOffice, M7046, WS, WSReplica, WSStore, POS, 
navprodbo01 stopped services: 
---
navprodbo02 running services: BackOffice, WS, WSReplica, WSStore, POS, 
navprodbo02 stopped services: M7046, 
---
navprodbo03 running services: BackOffice, WS, WSReplica, WSStore, POS, 
navprodbo03 stopped services: M7046, 
---
navprodbo04 running services: BackOffice, WS, WSReplica, WSStore, POS, 
navprodbo04 stopped services: M7046, 
---

PS C:\Windows\system32> 

Comment List
Anonymous
Related
Recommended