I have some PS scripts that do different IIS related things on multiple servers at the same time. So, before anything I’m making a backup of IIS, via the
Backup-WebConfiguration -Name $backupname-$timestamp
As I could run more scripts many times on all servers, it creates a lot of backups. That’s not the problem. My problem (using the example above) is that the $timestamp variable to make each backup unique (because it will error if I give the same name each time) is set up as follows:
$timestamp = get-date -Format 'dd.MM.yyy-HH.mm.ss''
$backupname is the name of the application the script works on - usually a website name. ie - utilities.com etc
That makes it quite unique even if I ran another script 1 second later.
The problem is that if I run a script on about 10 servers, the backups are all slightly different file names (a couple seconds different, changes the file name) This is fine, but when it comes to do a restore, I need to be able to restore on ALL 10 servers at once - ie, find the same backup set - so all are restored to before THAT script was run, ie. that backup.
So I need a way to create a unique backup file each time on ALL servers, that is named the same. So if I do a restore, I can use the same name on all servers.
I’m just stumped, thinking of how…
I’d have to check set some kind of starting counter, and add that to a variable to add to the end of Backup-Webconfiguration -Name $string
I guess I’d need an equal starting point on ALL servers too - ie. check the backup file names first?
Perhaps I should do the backup, then just rename it to a file with an incrementing counter - that way it renames on all servers at the same time it runs the script on all servers?
But I just cant figure out where to start… any ideas or advice would be greatly appreciated!