How To Make POWERSHELL MONITORING Script Look Amazing in 2 hours?

Since 15 September 2019, everyone can subscribe and download the Poshland Monitoring script. It’s the universal Powershell monitoring script. This tool helps quickly prepare the Windows Servers health report. If you want to use the Powershell Monitoring Script, you should understand Powershell functions.

Didn’t you download Poshland Monitoring script yet? It’s available on Poshland Resources.

In this post, I would like to show you how to place your Powershell function to the Poshland Monitoring script and generate the first health report.

Powershell monitoring example

I will show you how to generate the first health report based on Active Directory domain controllers. To do this, you need to create your Monitor Pack.

The Monitor Pack in the PoshlandMonitoring tool is a folder with custom Powershell functions to check health for a specific group of servers.

To create the new Poshland Monitor Pack, you have to copy and paste the MP-MonitorPackTemplate directory.

You can rename the copied folder as you prefer, but the name has to start from ‘MP-‘.

In this example, I rename it to MP-ActiveDirectory.

copy monitor pack

Prepare your Powershell functions

Now you have to prepare your custom functions. 

If you don’t know how to write Powershell function, please read post Many repetitive tasks? Create Powershell functions​.

You have to know two requirements. 

The function always has to contain $Server param.

The function has to return one of the values.

  • ‘Pass’ – the cell background color will be Green.
  • ‘Warn’ – the cell background color will be Yellow.
  • ‘Fail’ – the cell background color will be Red.
  • other value – the cell background color will be white.

I wrote a few basic Powershell functions to check Active Directory health.

I don’t write about the best practices to monitor Active Directory. My functions are very simple to show how to work with the Poshland Monitoring tool.

You can write and test your Powershell function in Powershell console.

The first Powershell function, I want to run a test of resolving the domain controller name.

function CheckDNS {
    param (
    $result = "Fail"
	$ip = @([System.Net.Dns]::GetHostByName($ServerName).AddressList | Select-Object IPAddressToString -ExpandProperty IPAddressToString)
	if ($ip -ne $null ){$result = "Pass"}

    return $result
check dns Powershell function

In the next Powershell function, I want to test connectivity by the Ping.exe tool.

function CheckPing {
    param (
    $result = "Fail"
    $ping = new-object
    $reply = $ping.Send($ServerName)
    if ($reply.status -eq "Success")
        $result = "Pass"


    return $result
Powershell function to check ping

In the third Powershell function, I want to check the status of Active Directory services. If some service is not running, the function will return Fail.

function CheckDCServices {
    param ( 
		$servicesrunning = @()
		$servicesnotrunning = @()
		$servicesToCheck = @(
		try {
			$servicestates [email protected](Get-WmiObject -ComputerName $server -Class Win32_Service -ErrorAction STOP | where {$services -icontains $_.Name} | select name,state,startmode)

			$ServiceHealth = "WMIFail"

		if (!($ServiceHealth)) {
			$servicesrunning = @($servicestates | Where {$_.StartMode -eq "Auto" -and $_.State -eq "Running"})
			$servicesnotrunning = @($servicestates | Where {$_.Startmode -eq "Auto" -and $_.State -ne "Running"})
			if ($($servicesnotrunning.Count) -gt 0){

				$ServiceHealth = "Fail"	
			 else {
				$ServiceHealth = "Pass"

   return $ServiceHealth

check active directory services

In the last Powershell function, I want to check if SYSVOL and NETLOGON share are available.

function CheckDCShare {
    param ( 
        [string[]]$sharesName = ("NETLOGON","SYSVOL")

    foreach ($Share in $sharesName) {
        [string[]]$PathArray += "\\$Server\$Share" 

    if ((Test-Path $PathArray -ErrorAction SilentlyContinue) -contains $false) {
        $State = "Fail"
    else {
        $State = "Pass"

    return $State
check Domain controllers share

Paste your Powershell functions into the Poshland Monitoring script

Now you can copy and paste your Powershell functions to functions.ps1 file located in the new Monitor Pack directory.

The Powershell monitoring script should be able to invoke custom functions that you prepared. The main PowershellMonitoring.ps1 script invokes them using RunCheck.ps1 file from the MonitorPack directory.

$serverObj = New-Object PSObject
$serverObj | Add-Member NoteProperty -Name "Server" -Value $server
$serverObj | Add-Member NoteProperty -Name "CheckDNS" -Value (CheckDNS -Server $Server)
$serverObj | Add-Member NoteProperty -Name "CheckPing" -Value (CheckPing -Server $Server)
$serverObj | Add-Member NoteProperty -Name "CheckDCServices" -Value (CheckDCServices -Server $Server)
$serverObj | Add-Member NoteProperty -Name "CheckDCShare" -Value (CheckDCShare -Server $Server)
poshland monitoring tool

The last two steps

Before running the Powershell monitoring script, you have to do the last two steps.

The first one is specifying the servers list. You can do this in two ways. Create a dedicated Active Directory group and add Computer objects or add server names to the Servers.List file. I will show you the second way.

The second and the last step is setting a report name in the param.ini file.

define report name

Now the Monitor Pack is ready. You can run the main PowershellMonitoring.ps1 and see the final health report for domain controllers.

run Powershell monitoring


Finally, you can generate the Windows server health report using PoshlandMonitoring. You can send the health report by email. I will show you this step in the next article. If you don’t know why I wrote the Powershell monitoring script, go to the article Short Story: The Truth About my POWERSHELL MONITORING.

What do you think about Poshland Monitoring? Please leave a comment.

Get Access to Poshland Resources for FREE!!!

Signup now and receive an email once I publish new content.

I agree to have my personal information transfered to MailerLite ( more information )

I will never give away, trade or sell your email address. You can unsubscribe at any time.