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

powershell Get Envirennement Variable from Notification's placeholders

Votes:

0

Hello,

I have a script powershell to purge Exchnage Logs, and I configured a Notification template to launch this script on the Exchange servers when the Espace disk sesnsors "C:" get error status,

My script is the follow :


# Set-Executionpolicy RemoteSigned

# Utilisateur :
$username = "Domine\Administrator_Account" 

# Le chemin du fichier script pour purger les logs exchange :
# $exchLogPurgeCodePS = "C:\Program Files (x86)\PRTG Network Monitor\Notifications\EXE\exch_2013_purge_logs_15j.ps1"

# l'IP ou Nom DNS du serveur Exchange diatant
#$RemoteComputers= "@IP_EXCH_SRV"
# param(
# [string]$RemoteComputers = $host
# )
<#
# TODO  : 
#  
param(
[string]$RemoteComputers = %host
)
#>
$Env:RemoteComputers = $host
# [Environment]:SetEnvironmentVariable('RemoteComputers',$host)
# Chiffrer le MDP du compte Admin, et le mettre dans le fichier "cryptedpass.txt"
<#
$cryptedpass = $userPassword | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File "cryptedpass.txt"
echo $cryptedpass
#>

$pass = Get-Content "cryptedpass.txt" | ConvertTo-SecureString
$File = "cryptedpass.txt"
$MyCredential = New-Object -TypeName System.Management.Automation.PSCredential `
 -ArgumentList $userName, (Get-Content $File | ConvertTo-SecureString)
 echo $MyCredential


<# S'il y a plusieurs serveurs surlesquels il faut lancer le script

$RemoteComputers= get-content "servers.txt"
#>


# Tester la connxion WMI sur tous le(s) serveur(s)
ForEach ($RemoteComputer in $RemoteComputers)

{

If (Test-WSMan -ComputerName $RemoteComputer)

{
echo "CONNECTION TO SERVER...."
# Connexion au serveur distant via l'objet (Variabel) "$MyCredential" 
Invoke-Command -ComputerName $RemoteComputer -Credential $MyCredential -ScriptBlock {

##############################################  
HERE MY SCRIPT TO PURGE EXCHANGE LOGS
##############################################


}

}

}



In my script I tried to pass PRTG %host placeholder to Powershell as following, but I never succeeded to do it.

##### 1. 
# param(
# [string]$RemoteComputers = $host
# )

##### 2.
<#
param(
[string]$RemoteComputers = %host
)
#>

##### 3.
#$Env:RemoteComputers = $host


##### 4.
# [Environment]:SetEnvironmentVariable('RemoteComputers',$host)

So, I hope you can help me on this case, can you guide me how can I use Notificatiosn's placeholders in my powershell code please ?

Thank you very much.

Best regards,

placeholdersinpowershell placeholderspowershll prtgplaceholders

Created on Apr 17, 2022 9:49:53 AM



2 Replies

Votes:

0

Hi,

To passe the device'IP to my script powershell, in my script I tried again like follow :

# Set-Executionpolicy RemoteSigned
$username = "domaine\administrateur" 


param(
[string]$host
)

and in my notification template I did :

# Execute Program : 
Program File : MyScript.ps1

parameters  : '%host'


I wait that the sensor get error status to launch the notification that used for this script.

Created on Apr 21, 2022 6:50:00 AM



Votes:

0

Have you tested your script outside of PRTG?
Is the problem only with the placeholder for the device address, or do you get a error in PRTG for this notification type?


Kind regards,
Sasa Ignjatovic, Tech Support Team

Created on Apr 25, 2022 9:01:20 AM by  Sasa Ignjatovic [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.