Adding website and FTP in IIS 7 via script

We are moving over 100 domains to the new server. I created a script that will allow you to add a website entry and FTP login in IIS 7 using a simple BAT file. I found several tutorials using ADC SITE, which works very well. By running :: c: \ scripts \ createIIS.bat youdomainname.com. Any feedback? - He works.

@Echo off :: -------------------------------------------- :: Create IIS 7 Site Entry / FTP Site :: -------------------------------------------- :: Get variable from command %1 Root Domain Name. set rootDomainName = %1 :: This is the path to the Web Pages on the server. set WebFile=C:\websites\ :: ADD NEW Directory MKDIR %WebFile%%1 :: ADD IIS ENTRY %windir%\system32\inetsrv\AppCmd ADD SITE /name:%1 /bindings:http/*:80:%1,http/*:80:www.%1 /physicalPath:C:\websites\%1 :: -------------------------------------------- :: CREATE FTP in IIS :: -------------------------------------------- %windir%\system32\inetsrv\AppCmd add vdir /app.name:"Default FTP Site/" /path:/%1 /physicalPath:"%WebFile%%1" echo New Directory Created: %WebFile%%1 echo IIS Website Created: %1 and www.%1 echo FTP SITE Created: %1 echo ... echo ... echo COMPLETED! pause 
+6
source share
1 answer

Great script. Despite the fact that this is not a question, I slightly changed it for batch processing.

First, I created a batch file that reads in the text file of the sites to be added, which refers to your slightly modified batch file just for creating websites (FTP is not required):

 @Echo off :: --------------------------------------------------------------------------------------- :: Create Batched IIS 7 Site Entries :: :: Usage: CreateIISEntry.bat [websitename.com] (no www.) :: for /f %%X in (NewWebsiteEntries.txt) do CreateSingleIISEntry.bat %%X echo ... echo *** BATCH PROCESS HAS BEEN COMPLETED *** 

NewWebsiteEntries.txt contains a list of created websites - one per line (without www):

 site1.com site2.com site3.com 

Finally, a batch file that creates entries:

 @Echo off :: --------------------------------------------------------------------------------------- :: Create IIS 7 Site Entry :: :: Usage: CreateSingleIISEntry.bat [websitename.com] (no www.) :: --------------------------------------------------------------------------------------- :: Get variable from command %1 Root Domain Name. set rootDomainName = %1 :: This is the path to the Web Pages on the server. set WebFile=C:\inetpub\wwwroot\ :: ADD NEW Directory MKDIR %WebFile%%1 echo New Directory Created: %WebFile%%1 xcopy C:\inetpub\wwwroot\NewWebsiteHolding\*.* %WebFile%%1 :: ADD IIS ENTRY %windir%\system32\inetsrv\AppCmd ADD SITE /name:%1 /bindings:http/[YOUR IP ADDRESS OR *]:80:%1,http/[YOUR IP ADDRESS OR *]:80:www.%1 /physicalPath:%WebFile%%1 echo IIS Website Created: %1 and www.%1 #:: -------------------------------------------- #:: CREATE FTP in IIS #:: -------------------------------------------- #%windir%\system32\inetsrv\AppCmd add vdir /app.name:"Default FTP Site/" /path:/%1 /physicalPath:"%WebFile%%1" # # #echo FTP SITE Created: %1 echo ... echo ... echo New website added ========================= %1 

Since in my case not all new sites will live immediately, by default I placed a site whose contents are copied to recently created site directories.

This will add all sites to the default application pool.

What about that.

+5
source

Source: https://habr.com/ru/post/898600/


All Articles