MENU

Folder-MirrorToMultipleLocations

I wrote this PowerShell script years ago and it has been running ever since with no problems so far. There is a nightly restart of the script just in case. It handles a very large media folder (hundreds of thousands of files, 100,000+ subfolders) and frequently added files that need to be synced to multiple destinations. There might be some pieces you can use? Basically it uses FSW (FileSystemWatcher) to watch for new files created on Server01, and then builds RoboCopy commands to run that will copy the file to multiple destination servers (i.e. Server02 and Server03). It is no doubt really poorly written (always learning PowerShell), inefficient and laughable code – but it has so far been working great for my application. I should really go back and refactor it at some point :/ # Synopsis Monitor master folder (including subfolders) and sync any changes to multiple remote shares using RoboCopy. # Description Sets up a FileSystemWatcher on “mediafolder” that monitors this directory and all subdirectories for the created/changed/renamed/deleted file events only (not directory events). This happens every x amount of seconds (can be set in variables below). When an event is noticed, it is processed and if OK […]
Read More ›

Cleanup-Desktop

Keep your desktop clean by scheduling this script to run each time you log on to your PC, or any other schedule you’d prefer. Move all files/folders to their respective monthly folders in -ArchiveFolder based on the LastWriteTime of each file/folder – except files/folders with a LastWriteTime newer than the number of days passed in as a Parameter -DaysToKeep. The script can be found at my GitHub repo, link below… Cleanup-Desktop script on GitHub
Read More ›

Install-Application

With a need to install an exe (in particular Microsoft’s ATP – Advanced Threat Protection installer) silently at startup (only if the required version isn’t already installed); I ended up finding a script written by Dan Scott-Raynsford (https://dscottraynsford.wordpress.com/). It worked OK but wasn’t perfect for my needs due to 2 issues; one being the spaces in the installer exe filename and the other being the use of quotes in the arguments needed to be supplied in the full installation string. The spaces in the filename could easily be resolved by editing the filename but I needed to make the passing in of multiple peculiar arguments more straight-forward anyway, therefore I may as well make the script as robust as possible. The modified script to allow for these requirements plus some extra features and more verbose logging can be found at my GitHub repo, link below… Install-Application script on GitHub
Read More ›

Manage-Service

I had a software vendor supply us with a method of restarting the services for their application each night via a batch file that just: Performed a TASKKILL on 27 processes across 6 remote machines Called an external SLEEP.EXE file for a dumb wait period of 240s Then finally called another batch file that ran an SC START over the 27 services This would hopefully result in restarted services. It worked … sometimes. When it didn’t work, we were unsure why because there was no logging. This isn’t really the greatest solution; so I set about replacing this with a PowerShell script to manage the services, not just for this particular piece of software but to make it generic so it can be used for any service(s)/computer(s). It allows you to send ‘Start’, ‘Stop’, ‘Restart’, ‘Pause’ or ‘Resume’ actions to a service on the local or remote computer. I included complete logging, error handling and an optional force kill option if the service doesn’t stop nicely after x seconds. See my GitHub repo below for more info…   Manage-Service script on GitHub
Read More ›