1

Can someone help me with backup of IIS on multiple servers from powershell script remotely. I can take backup of IIS from powershell command.

backup-webconfiguration -name IIS_backup.

Also i have a batch script which takes backup but that works only for one server . I have to login locally and run this as a batch job.

@echo off cls pushd "%WinDir%\System32\inetsrv" echo.| date | find /i "current">datetime1.tmp echo.| time | find /i "current">datetime2.tmp for /f "tokens=1,2,3,4,5,6" %%i in (datetime1.tmp) do ( echo %%n>datetime1.tmp ) for /f "tokens=1,2,3,4,5,6" %%i in (datetime2.tmp) do ( echo %%m>datetime2.tmp ) for /f "delims=/ tokens=1,2,3" %%i in (datetime1.tmp) do ( set TMPDATETIME=%%k%%i%%j ) for /f "delims=:. tokens=1,2,3,4" %%i in (datetime2.tmp) do ( set TMPDATETIME=D%TMPDATETIME%T%%i%%j%%k%%l ) appcmd add backups %TMPDATETIME% del datetime1.tmp del datetime2.tmp set TMPDATETIME= popd echo. 

Currently i have worked on these two scripts . If possible please help me with taking backup of IIS remotely on multiple servers either through powershell or batch file.

0

1 Answer 1

1

Provided PSRemoting is enabled on your web servers you can simply run the following command to run the backup on multiple computers:

invoke-command -ComputerName "webserver1","webserver2","webserver3" -Scriptblock {Import-Module WebAdministration; backup-webconfiguration -name IIS_backup} 

You can also separate your server list from the command as follows:

$Computers = "webserver1","webserver2","webserver3" invoke-command -ComputerName $Computers -Scriptblock {Import-Module WebAdministration; backup-webconfiguration -name IIS_backup} 

You can then populate the $Computers variable in a variety of ways. For instance, from a text file or from and AD query.

2
  • Thanks for help. Code works fine. Is it possible to place the backup of iis on different location . Having said that if i am taking backup of multiple servers at a time then backup is getting created at location C:\windows\system32\inetsrv\backup\. So i want to place all servers backup on different servers as well so that if any issue occurs with IIS we can use restore from there. Commented Dec 30, 2014 at 21:50
  • Perhaps you could copy the backup it creates using copy-item? Commented Dec 31, 2014 at 3:39

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.