The script can be used to export IIS configurations, task schedules, service lists, and apps, while supporting Windows 2003 and 2008.
#Define Backup Location$iisfolder="D:\Backup_all\IIS"$taskfolder="D:\Backup_all\Task"$servicesfolder="D:\Backup_all\Service"$appfolder="D:\Backup_all\app"#define where the source app files are located$app _sourcefolder="D:\DDservice"#New FolderIf(! (Test-path$iisfolder) ) {mkdir$iisfolder}If(! (Test-path$taskfolder) ) {mkdir$taskfolder}If(! (Test-path$servicesfolder) ) {mkdir$servicesfolder}If(! (Test-path$appfolder) ) {mkdir$appfolder}#export a list of services$servicepath=$servicesfolder+"\services_list.txt"Get-service |ft Displayname,name,status-wrap | Out-file $servicepath#Backup App$CurrentPath=$MyInvocation. MyCommand.Path.substring (0,$MyInvocation. MyCommand.Path.LastIndexOf (' \ ') +1)$uncopyfile= Join-path$CurrentPath Backup_all_uncopy.txt$apppath=$appfolder+"\"xcopy/e/h/r/s/y/exclude:$uncopyfile $app _sourcefolder\*.*$apppath $Version= [System.Environment]::OSVersion.Version.MajorIf($Version -ne5){#To back up the IIS configuration, use the Appcmd Restore backup command to restore the IIS configuration: appcmd Restore Backup BackupName$iispath=$iisfolder+"\"New-alias-name Appcmd-value$env: windir\system32\inetsrv\appcmd.exeappcmd Add backupxcopy/s/y C:\Windows\System32\inetsrv\backup$iispath#Export a task schedule, use the Schtasks/create command to import a task plan$Schedule= new-object-com"Schedule.service"$Schedule. Connect ()$Schedules=$Schedule. GetFolder ("\"). Gettasks (0)If($TaskName -eq $null){ Foreach($task inch $Schedules) { $taskname=$task. Name$taskpath=$taskfolder+"\"+$taskname+". XML"cmd/C"chcp 437 >null && schtasks/query/xml one/tn""$taskname"" "|out-file $taskpath }}}Else{#Backup Task Schedule, copy the backed up files to C:\WINDOWS\Tasks to complete the restore$taskpath=$taskfolder+"\"xcopy/s/y C:\WINDOWS\Tasks$taskpath#backing up the IIS configuration, using Iiscnfg/import to restore the IIS configuration#Example:cscript.exe c:\windows\system32\iiscnfg.vbs/import/f d:\i.xml/sp//children/d DD123/DP/$time= Get-date-uformat"%y%m%d%h%m"$iispath=$iisfolder+"\"+"iisconfig03_"+$time+". XML"cscript.exe C:\Windows\System32\iiscnfg.vbs/export/f$iispath/SP//CHILDREN/D DD123}
The backup_all_uncopy.txt file is placed in the same directory as the above script, which reads as follows:
\log\
\logs\
Back Up server data (IIS configuration, Task Scheduler, Service list, and app)