Powershell - ms_flow_filewatcher.ps1

$watcheron = New-Object System.IO.FileSystemWatcher
$watcheron.Path = "C:\Lock\"
$watcheron.Filter = "on.txt"
$watcheron.IncludeSubdirectories = $true
$watcheron.EnableRaisingEvents = $true  

$watcheroff = New-Object System.IO.FileSystemWatcher
$watcheroff.Path = "C:\Lock\"
$watcheroff.Filter = "off.txt"
$watcheroff.IncludeSubdirectories = $true
$watcheroff.EnableRaisingEvents = $true

$actionon = {
    Write-Host "on"
    ./plink.exe -i "C:\putty_priv.ppk" [email protected] sudo /root/mainton.sh
}    

$actionoff = {
    Write-Host "off"
    ./plink.exe -i "C:\putty_priv.ppk" [email protected] sudo /root/maintoff.sh
}    

Register-ObjectEvent $watcheron "Created" -Action $actionon
Register-ObjectEvent $watcheroff "Created" -Action $actionoff

while ($true) {
    $On = "C:\Lock\on.txt"
    if (Test-Path $On) {
        Remove-Item $On
    }

    $Off = "C:\Lock\off.txt"
    if (Test-Path $Off) {
        Remove-Item $Off
    }
    sleep 5
}