IIS backup on Multiple servers from Powershell

batch-fileiispowershell

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.

Best Answer

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.