IISUtil.psm1
|
Import-Module -Name WebAdministration function CreateAppPoolIfNotExists($iisAppPoolName) { try { Push-Location $iisAppPoolDotNetVersion = "v4.0" Set-Location IIS:\AppPools\ if ((Test-Path $iisAppPoolName -pathType container) -eq $true) { Write-Host "$iisAppPoolName AppPool Exists" return; } # create the app pool $appPool = New-Item $iisAppPoolName $appPool | Set-ItemProperty -Name "managedRuntimeVersion" -Value $iisAppPoolDotNetVersion Write-Host "$iisAppPoolName AppPool Created" } finally { Pop-Location } } function CreateSiteIfNotExists($iisAppName, $iisAppPoolName, $directoryPath, $domain) { try { Push-Location Set-Location IIS:\Sites\ if ((Test-Path $iisAppName -pathType container) -eq $true) { Write-Host "$iisAppName Site Exists" return } # create the site $iisApp = New-Item $iisAppName -bindings @{protocol="http";bindingInformation=":80:" + $domain} -physicalPath $directoryPath $iisApp | Set-ItemProperty -Name "applicationPool" -Value $iisAppPoolName Write-Host "$iisAppName Site Created" } finally { Pop-Location } } function CreateFilePathIfNotExists($filePath) { if ((Test-Path $filePath -pathType container) -eq $true){ Write-Host "$filePath FilePath Exists" return; } New-Item -ItemType Directory -Force -Path $filePath Write-Host "$filePath FilePath Created" } function DeleteSite ($siteName) { try { Push-Location Set-Location IIS:\Sites\ Remove-Item $siteName -Confirm:$false -Recurse:$true Write-Host "$siteName Site Deleted" } finally { Pop-Location } } function DeleteAppPool ($appPool) { try { Push-Location Set-Location IIS:\Sites\ Get-ChildItem IIS:\Sites | ForEach-Object { if ($_.applicationPool -eq $appPool) { DeleteSite $_.Name } } Set-Location IIS:\AppPools\ Remove-Item $appPool -Confirm:$false -Recurse:$true Write-Host "$appPool AppPool Deleted" } finally { Pop-Location } } function CreateSiteAndPoolIfNotExists($appName, $directoryPath, $domain) { CreateAppPoolIfNotExists $appName CreateSiteIfNotExists $appName $appName $directoryPath $domain CreateFilePathIfNotExists $directoryPath } |