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.
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.

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 (
[string]$ServerName
)
$result = "Fail"
$ip = @([System.Net.Dns]::GetHostByName($ServerName).AddressList | Select-Object IPAddressToString -ExpandProperty IPAddressToString)
if ($ip -ne $null ){$result = "Pass"}
return $result
}

In the
function CheckPing {
param (
[string]$ServerName
)
$result = "Fail"
$ping = new-object system.net.networkinformation.ping
$reply = $ping.Send($ServerName)
if ($reply.status -eq "Success")
{
$result = "Pass"
}
return $result
}

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 (
[string]$Server
)
$servicesrunning = @()
$servicesnotrunning = @()
$servicesToCheck = @(
"ntds",
"adws",
"dns",
"dhcpserver"
)
try {
$servicestates [email protected](Get-WmiObject -ComputerName $server -Class Win32_Service -ErrorAction STOP | where {$services -icontains $_.Name} | select name,state,startmode)
}
catch
{
$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
}

In the last Powershell function, I want to check if SYSVOL and NETLOGON share are available.
function CheckDCShare {
param (
[string]$Server,
[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
}

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)

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

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

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

Conclusion
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.