mardi 18 août 2020

Powershell - If statement, returning count result in a popup

i'm learning powershell by trying to automate some jobs/problems i encounter at work. I wanted to count periodically if there are any .ERR file(s) in a particular folder and if there was, create a popup box with the quantity of that count result.

So i created a script to count the files in the folder, no problem. I also created a script to generate a popup box but when i combine the two in an If statement i no longer get a popup box and my powershell console returns a 1 after running the script?

My script is as follows:

$errchk = Write-Host ( Get-ChildItem c:\PS\test\*.ERR | Measure-Object ).Count
$str1 = "Number of .ERR files: "
If ($errchk -gt 0)
    {$wsh = New-Object -ComObject Wscript.Shell
    $wsh.Popup($str1+$errchk,0,"WDServer Error",0)}

Aucun commentaire:

Enregistrer un commentaire