Server/Windows Server

[PowerShell] IIS 웹사이트 자동 설정

달빛에취하다 2017. 5. 23. 12:06

PowerShell를 이용한 IIS 웹사이트 자동 설정 방법 입니다.

PowerSheel 파일은 D:\IIS_SETTING.ps1 으로 지정되어 있습니다.


PowerShell 파일(.ps1) 처리 내용은 

1. 폴더 생성

2. Application Pool 생성

3. Site 생성

4. Site내 Application 추가


---------------- BAT 파일 ---------------------

@echo off

setlocal


@echo IIS 설정 페이지 입니다.


set /p str=프로젝트명칭(Html URL 에 사용가능한)을 입력하세요:


IF "%str%" == "" GOTO Error


Powershell.exe -noprofile -executionpolicy  bypass -file "D:\IIS_SETTING.ps1" "%str%"


:Error

@echo 프로젝트 명칭은 필수 입니다.

pause

---------------- BAT 파일 끝 ------------------



---------------- PowerShell 파일 ----------------

[string]$name=$args

[string]$nameupper = $name.ToUpper("euc-kr");

[string]$webroot = "D:\wwwRoot\Project\$nameupper\Application";

[string]$serviceroot = "D:\wwwRoot\Project\$nameupper\WS";

[string]$fileroot = "D:\Upload Files\$nameupper";

[string]$sitename = "kr.d-0-b.$name"

[string]$url = $name+".d-0-b.kr"


#Set-ExecutionPolicy RemoteSigned;


import-module WebAdministration;


mkdir "$webroot";


mkdir "$serviceroot";


mkdir "$fileroot";


IIS:


echo $sitename;


Set-Content -LiteralPath "$webroot\index.html" -Value "<br /><br /><br /><br /><br /><center>$name.d-0-b.kr";


New-WebAppPool $sitename;


New-Website -Name "$sitename" -Port 80 -PhysicalPath "$webroot" -ApplicationPool "$sitename" -HostHeader $url;


New-WebApplication -Name "WS" -Site "$sitename" -PhysicalPath "$serviceroot" -ApplicationPool "$sitename";

---------------- PowerShell 파일 끝 -------------