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,
Add comment