What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags

View all Tags

nslookup Pass Parameter from EXE Sensor to .bat file



Your Vote:




Ok, I've created .bat file:

@echo off
for /F "tokens=2" %%a in ('nslookup bbc.co.uk') do (
  set value=%%a 
echo 0:%value%

This is stored on the PRTG server.

I've then created an EXE/Script sensor using the .bat. It works perfectly and shows the correct IP of bbc.co.uk

What I want to do is use the Parameters field on the PRTG sensor so I can use this multiple times for many DNS entries / URLs.

What should I use in the sensor and how should the .bat be amended to add a variable in to be passed by the sensor?



batch custom-script-exe prtg

Created on Sep 22, 2016 1:17:07 PM by  CMP (0) 1

Last change on Sep 23, 2016 10:26:24 AM by  Stephan Linke [Paessler Support]

2 Replies



Your Vote:



Please stop using batch, you're only making your life harder :) Do yourself a favor and use PowerShell:

# the parameters of the script
param([string[]]$hosts = @("www.google.de","bbc.co.uk"), $DNS = "")

# create a new list object where the hosts are added 
$list = New-Object System.Collections.ArrayList($null)

# Foreach Domain in the $hosts array...
Foreach($Domain in $hosts){

    # Resolve the DNS name using the given DNS server. Only select the A records
    $Results = (Resolve-DnsName -Server $DNS -NoHostsFile $Domain | Select Name,IPAddress,Type | Where {$_.Type -eq "A"})
    # Now add every result to the lists. Since one domain can have multiple A-records or IPs, we need to split this. 
    foreach($Result in $Results)
    { $list.add("[$($Result.Name) - $($Result.IPAddress)]") | Out-Null; }

# Output it to PRTG. Example output: 
# 0:[www.google.de -] [bbc.co.uk -] [bbc.co.uk -] [bbc.co.uk -] [bbc.co.uk -]
Write-Host "0:$($list -join " ")";

A quick introduction to PowerShell Sensors in PRTG can be found here.

Created on Sep 23, 2016 10:49:02 AM by  Stephan Linke [Paessler Support]



Your Vote:



Haha. I agree. I found that batch file code from a previous KB on here, but it didn't pass parameters.

All sorted with the PS script

Many thanks


Created on Sep 23, 2016 11:19:46 AM by  CMP (0) 1

Please log in or register to enter your reply.

Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.