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,


Article Comments

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.


Apr, 2022 - Permalink

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


Apr, 2022 - Permalink