Backup-WebConfiguration (incrementing) ?

Hi Folks,

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 '''

$backupname is the name of the application the script works on - usually a website name. ie - 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!




How are you starting the scripts on the remote servers?

Can you not just get the timestamp on the calling computer and pass it to all the remote machines with $using?

It’ll be something like this:

$timestamp = get-date -Format '''
$backupname = 'MyApplication'

Invoke-Command -ComputerName server01,server02,server03 -ScriptBlock { Backup-WebConfiguration -Name "$using:$backupname-$using:timestamp" }

I don’t have a another machine to test on so I suspect the syntax is a bit wonky, but that should give you an idea.

As for this…

I need to be able to restore on ALL 10 servers at once

… this is what PS sessions / jobs / parallel processing is all about.

Hey Matt, Yes - that is the easiest solution. I’ll pass the timestamp from the ‘script running server’, so it gets a unique value there and then - then sends to the other servers to create the backupname ! Sweet ! I should have thought of that. Now, at least all backups have the exact unique name, and then a restore, I only need to request the same value in the variable, and all 10 servers would be restored with that same back up file!

PS. I’m using a fantastic tool called System Frontier, from Noxigen LLC. It’s a role based access model web app to manage servers, but the coolest part is the front end to powershell scripts (it creates the HTML form and everything! Really worth a look, if you need that type of setup - plus their support is top notch!

Thanks for all who replied, this forum is always super friendly and non judging ! :slight_smile:

Have a great week folks!