'script para sincronizar todos os IIS, varios sites,servidores e bindings 'Author: Felipe Ferreira 'Data: 13/04/2010 'Version: 4.1 'Requires: c:\scripts\iismt (IIS 6 RSKit tool), a Source IIS Server to replicate from 'TODO: 'OK - Check if Site exists, if so Delete it before import 'OK - Execute remotely by another script, psexec (iis_alinhar.vbs, alinhar_todos_iis.bat) 'Variables dim verbose : verbose = 1 '(1 verbose, 0 silent) dim id,ip,hostname,shell dim arSite(6) Dim arBind(6) id = 0 'Get local hostname set shell = WScript.CreateObject( "WScript.Shell" ) hostname = shell.ExpandEnvironmentStrings("%COMPUTERNAME%") 'Site arSite(1) = "RealShow" arSite(2) = "Club" arSite(3) = "ClubeMobile" arSite(4) = "NewsExtra" arSite(5) = "NewsOnline" arSite(6) = "Mobile" 'Binds arBind(1) = "RealShow." & hostname & ",RealShow.NewsOnline.globo.com" arBind(2) = "club." & hostname & ",clube.NewsOnline.com.br,clube.NewsOnline.globo.com" arBind(3) = "mclub."& hostname & ",mclube.NewsOnline.globo.com,clube.NewsOnline.mobi" arBind(4) = "NewsExtra." & hostname & ",NewsExtra.globo.com" arBind(5) = "NewsOnline" & hostname & ",NewsOnline.globo.com,www.NewsOnline.com.br,www3.NewsOnline.com.br,www2.NewsOnline.com.br,NewsOnline.com.br,canal.NewsOnline.com.br,www.globon.com.br,www.globoon.com.br" arBind(6) = "mobi." & hostname & ",NewsOnline.mobi,mNewsOnline.globo.com" For k=1 to 6 'ciclo para Sites ip = getip(arSite(k)) pt "|----------------------------------------------------------------------------------------" pt "|Server: "& hostname & " Site: " & arSite(k) & " IP: " & ip & " Bindings: " & arBind(k) call SetupIIS(hostname,arSite(k),arBind(k),ip) next '############################# SUBS AND FUNCTIONS ########################################### sub SetupIIS(strServer,strSite,strBind,intIP) id = getId(strSite) if id <> 0 then 'site já existe pt "WARNING, Site: " & strSite & " already exist,deleting it!" call deletesite(strSite) wscript.sleep 2500 id=x end if if id=0 or id=x or id=null then 'site não existe,criando pt vbcrlf & "CREATING, Site: " & strSite & vbcrlf call iismigrate(strSite,intIP) wscript.sleep 3600 id = getId(strSite) pt strServer & " : " & ip & " : " & id 'slipt bind aBind = split(strBind,",") pt vbcrlf & "Setting Binds..." &vbcrlf for each bind in aBind if id <> 0 then pt id & ", " &intIP&":80:" & bind call UpdateBindings(id,intIP&":80:" & bind) else pt "--------------------------------------------" pt "CRITICO, site nao foi criado corretamente! " pt "--------------------------------------------" exit sub end if next end if id = 0 end sub sub iismigrate(sitename,ips) dim strcmd Dim WshShell Set WshShell = CreateObject("WScript.Shell") 'EDIT HERE" SERVER SOURCE strcmd = "cmd /c c:\scripts\iismt SERVER162 " & sitename & " /configonly /overwrite /noninteractive /verbose /serverbindings " & ips &":80:" 'pt strcmd Set objExecObject = WshShell.Exec("cmd /c " & strcmd) 'Do While Not objExecObject.StdOut.AtEndOfStream ' pt objExecObject.StdOut.ReadLine() 'loop if err.number <> 0 then pt "Site: " & sitename & " migrated OK" end if Set WshShell = nothing End sub function getId(webName) set objWebApps = GetObject("IIS://localhost/W3SVC") For Each objWebApp In objWebApps If (objWebApp.KeyType = "IIsWebServer") Then 'wscript.echo objWebApp.Name If UCase( objWebApp.ServerComment ) = UCase( webName ) Then pt "Site: " & objWebApp.ServerComment & " ID: " & objWebApp.Name getId = objWebApp.Name else id = 0 end if End if next Set objWebApps = Nothing end function Sub UpdateBindings(WebSiteID, AdditionalBinding ) Dim objWebApp Dim intArraySize Dim arrOldBindings Dim arrNewBindings Set objWebApp = GetObject("IIS://localhost/w3svc/" & WebSiteID) If isArray(objWebApp.ServerBindings) then arrOldBindings = objWebApp.ServerBindings intArraySize = UBound(arrOldBindings) 'for each bind in arrOldBindings 'pt bind 'next Redim arrNewBindings(intArraySize + 1) For i = 0 to intArraySize arrNewBindings(i) = arrOldBindings(i) Next arrNewBindings(intArraySize + 1) = AdditionalBinding objWebApp.Put "ServerBindings", (arrNewBindings) objWebApp.SetInfo End If Set objWebApp = nothing End Sub Function GetIP(osite) hostname = lcase(hostname) osite = lcase(osite) Select Case hostname case "SERVER163" select case osite Case "RealShow" GetIP="172.16.83.16" Case "clubemobile" GetIP="172.16.83.26" Case "Club" GetIP="172.16.83.36" Case "NewsExtra" GetIP="172.16.83.46" Case "NewsOnline" GetIP="172.16.83.56" Case "mobile" GetIP="172.16.83.66" end select case "SERVER164" select case osite Case "RealShow" GetIP="172.16.83.17" Case "clubemobile" GetIP="172.16.83.27" Case "Club" GetIP="172.16.83.37" Case "NewsExtra" GetIP="172.16.83.47" Case "NewsOnline" GetIP="172.16.83.57" Case "mobile" GetIP="172.16.83.67" end select case "SERVER165" select case osite Case "RealShow" GetIP="172.16.83.18" Case "clubemobile" GetIP="172.16.83.28" Case "Club" GetIP="172.16.83.38" Case "NewsExtra" GetIP="172.16.83.48" Case "NewsOnline" GetIP="172.16.83.58" Case "mobile" GetIP="172.16.83.68" end select case "SERVER166" select case osite Case "RealShow" GetIP="172.16.83.19" Case "clubemobile" GetIP="172.16.83.29" Case "Club" GetIP="172.16.83.39" Case "NewsExtra" GetIP="172.16.83.49" Case "NewsOnline" GetIP="172.16.83.59" Case "mobile" GetIP="172.16.83.69" end select end select end Function sub deletesite(strSitep) Dim objAppPools, objAppPool Set WshShell = CreateObject("WScript.Shell") strcmd = "cscript //Nologo c:\scripts\iisweb.vbs /delete " & strSitep 'pt strcmd Set objExecObject = WshShell.Exec("cmd /c " & strcmd) if verbose = 1 then Do While Not objExecObject.StdOut.AtEndOfStream pt objExecObject.StdOut.ReadLine() loop end if Set WshShell = nothing WScript.Sleep 1000 call delAP(strSitep) End sub Function delAP(apname) On Error Resume Next dim obj,objpool set obj = GetObject("IIS://localhost/W3SVC/apppools") obj.delete "IIsApplicationPool",apname if err.number <> 0 then wscript.echo "Erro apagando Application Pool : " & apname & " Erro: " & err.number else pt "Application Pool " & ucase(apname) & " has been deleted" end if set obj = nothing End Function function pt(txt) if verbose = 1 then wscript.echo txt end if end function