What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

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

Run a script (eg powershell) on demand

Votes:

0

Hi all,

Been looking through the forums but have not found a way yet to achieve the following;

- I have a custom sensor which checks for blocked users with powershell, works great - I would like to send some kind of http(s) request to the prtg server which will run another powershell script to unlock the locked user, but only on demand, not automated.

The scripts are easy and already created and tested, see below. Thanks for any help in advance.

lockedusers.ps1:

Import-Module ActiveDirectory


$server=Search-ADAccount -Lockedout -UsersOnly | select SamAccountName
if ($server.count -eq $null -and $server -eq $null){
    $a=0
}
Elseif ($server.count -eq $null -and $server -ne $null){
    $a=1
    }
Else
{
    $a=@($server.count)
   }
Write-Host "<prtg>"
Write-Host "<result>" 
"<channel>Locked Out Users</channel>" 
"<value>"+ $a +"</value>" 
"</result>"
"<text>" + (($server | select SamAccountName | ConvertTo-Csv -NoTypeInformation | select -skip 1 ) -join ", ").replace("""","") + "</text>"
Write-Host "</prtg>"

unlock.ps1:

Search-ADAccount -LockedOut | Unlock-ADAccount

http-request manual powershell unlock users

Created on Jun 16, 2015 8:40:50 AM

Last change on Jun 16, 2015 8:58:05 AM by  Torsten Lindner [Paessler Support]



9 Replies

Votes:

0

Have a look at the HTTP Push Data (Advanced) sensor - configure the script to run as notification when the sensor receives a certain value and pass the data to the notification :)

Created on Jun 16, 2015 8:56:51 AM by  Stephan Linke [Paessler Support]



Votes:

0

Followed your suggestion. Log shows : Threshold Trigger sending Email,EXE (Sensor/Source/ID: 3500/3500/1).

But the locked account is still locked afterwards. Suggestions?

Created on Jun 16, 2015 10:10:46 AM



Votes:

0

I configured it this way, I can see how it should work. I do see that my script is being called but the account is not unlocked. Where can i find the logging on the script?

HTTP Push Data Advanced BETA Unlock On Demand Notification Info Threshold Trigger sending Email,EXE (Sensor/Source/ID: 3500/3500/1)

Should testing the notification also run the exe? I think so right? But thats not working either. Running the script through powershell on the probe does work... Any clue for me?

Created on Jun 16, 2015 11:41:15 AM



Votes:

0

Testing it should work as well, given that the parameters are correct and that the script works when executing on the command line - is that the case? Can you paste the parameters configured?

Created on Jun 16, 2015 12:45:08 PM by  Stephan Linke [Paessler Support]



Votes:

0

The script on its own should simply unlock all locked users, i wouldnt know what parameter to pass;

Import-Module ActiveDirectory Search-ADAccount -LockedOut | Unlock-ADAccount

When executing powershell.exe -File "c:\Program Files (x86)\PRTG Network Monitor\Notifications\EXE\og-unlock_users.ps1" it works just fine...

Created on Jun 16, 2015 12:53:37 PM



Votes:

0

Fair enough - is the PRTG service running as a different user without administrative permissions?

Created on Jun 16, 2015 1:31:18 PM by  Stephan Linke [Paessler Support]



Votes:

0

PRTG runs as local system account... Any suggestions to try?

Created on Jun 16, 2015 1:34:22 PM



Votes:

0

Supplying another account in the custom notification fixed the issue. Thanks for setting me on the correct path! It works like a charm now. Using iControl web I can now unlock user accounts from my Apple watch like any lazy admin should want :)

Created on Jun 16, 2015 2:20:57 PM



Votes:

0

Hehe glad that it's solved :)

Created on Jun 17, 2015 5:16:13 AM by  Stephan Linke [Paessler Support]




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.