Some Background Info - In case you are unfamiliar with the tools used in this answer. End the created PowerShell process when you no longer want it to run.You will see a console window flash, after they close the only indication it's running will be a couple new processes. Start-Process PowerShell.exe -verb Runas -argumentlist '-WindowStyle Hidden', '-NoExit', '-EncodedCommand', $encodedBlock $encodedBlock = ::ToBase64String(::Unicode.GetBytes($block)) You could have this script run at windows startup and it would be running in the background at all times without using a timer. Run the script, as long as the script is running that function will run (nearly instantly!) whenever a file or folder is changed in the watched folder. Change the Do-Something function to include your robocopy command or whatever. Change the $watchedFolder variable to the folder you want to watch. ps1, paste the script below into the file. This is good, since you have the great tool that is PowerShell, and a handy little cmdlet named Register-ObjectEvent.Ĭreate a text file, change the extension to.
0 Comments
Leave a Reply. |