Setup IIS App Pool and deploy codes by PowerShell


$iisSiteLocation = "D:\InetPub\wwwroot\iis\VirtualDirectories\" + $iisFolder"
$iisSite = "IIS:\Sites\My_Apps_Site (443)"

$NewAppPoolName = "My_Apps_Site_Service_AppPool"
CreateApplicationPool($NewAppPoolName)

CopyFilesWithWebConfigToIISLocation $sourceLocation $iisSiteLocation $appFolderName

function CreateApplicationPool([string] $AppPoolName){

$NewPool = Get-Item IIS:\AppPools\"$AppPoolName" -ErrorAction SilentlyContinue

Write-Host $AppPoolName

if($NewPool -eq $null) {
Write-Host "Creating Application Pool..."
New-WebAppPool -NameĀ $AppPoolName
$NewPool = Get-Item IIS:\AppPools\"$AppPoolName"
$cred = Get-Credential
$NewPool.ProcessModel.Username = $cred.GetNetworkCredential().Domain +"\"+ $cred.GetNetworkCredential().UserName
$NewPool.ProcessModel.Password = $cred.GetNetworkCredential().Password
$NewPool.ProcessModel.IdentityType = 3
$NewPool.ManagedRuntimeVersion = "v4.0"
$NewPool | Set-Item
}
Else {
Write-Host "Application Pool already exists."
}
}

 

function CopyFilesWithWebConfigToIISLocation ([string] $sourceDir, [string] $destDir, [string] $appFolderName) {
$sourceFileLocation = $sourceDir + "\" + $appFolderName
$destFileLocation = $destDir + "\" + $appFolderName

write-host "Copy files from " $sourceFileLocation " to " $destFileLocation
Copy-Item $sourceFileLocation $destDir -recurse -force
Copy-Item "$sourceFileLocation\WebConfig\PROD\web.config" $destFileLocation -force}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s