Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Set Parameters:
- $iisAppPoolName = "LSIntranet"
- $hostHeader = "" #without protocol, leave empty if neccessary
- $port = "4432" #set port (even if 443)
- $PipelineMode = "Integrated" # Integrated/Classic
- $AppPoolIdentity_Name = "<<Login>>"
- $AppPoolIdentity_Pass = '<<Password>>'
- $iisAppPoolDotNetVersion = "v4.0"
- #-------------------------------------
- $iisAppName = $iisAppPoolName
- $directoryPath = "C:\inetpub\wwwroot\" + $iisAppName
- Import-Module WebAdministration
- #navigate to the app pools root
- cd IIS:\AppPools\
- #check if the app pool exists
- if (!(Test-Path $iisAppPoolName -pathType container))
- {
- #create the app pool
- $appPool = New-Item $iisAppPoolName
- $appPool | Set-ItemProperty -Name "managedRuntimeVersion" -Value $iisAppPoolDotNetVersion
- $appPool.ManagedPipelineMode = $PipelineMode
- Write-Host "Application Pool was created." -ForegroundColor Green
- #set application pool identity
- $appPool.processModel.username = $AppPoolIdentity_Name
- $appPool.processModel.password = $AppPoolIdentity_Pass
- $appPool.processModel.identityType = 3
- $appPool | set-item
- Restart-WebAppPool $iisAppPoolName
- Write-Host "Application Pool was configured." -ForegroundColor Green
- }
- #navigate to the sites root
- cd IIS:\Sites\
- #check if the site exists
- if (Test-Path $iisAppName -pathType container)
- {
- return
- }
- #create the site
- New-item -Path $directoryPath -ItemType Directory
- if ($hostHeader) {
- $iisApp = New-WebSite $iisAppName -physicalPath $directoryPath -ApplicationPool $iisAppPoolName -Ssl -Port $port -HostHeader $hostHeader
- }
- else {
- $iisApp = New-WebSite $iisAppName -physicalPath $directoryPath -ApplicationPool $iisAppPoolName -Ssl -Port $port
- }
- Write-Host "Web site was created" -ForegroundColor Green
- Write-Host "Binding was configured" -ForegroundColor Green
- #Enable Windows auth
- Set-WebConfigurationProperty -filter "/system.webServer/security/authentication/windowsAuthentication" -name enabled -value true -PSPath "IIS:\" -location $iisAppName
- Write-Host "Windows Authentication was enabled" -ForegroundColor Green
- #Set "Connect As"
- Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/site[@name='$iisAppName']/application[@path='/']/virtualDirectory[@path='/']" -name "userName" -value $AppPoolIdentity_Name
- Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/site[@name='$iisAppName']/application[@path='/']/virtualDirectory[@path='/']" -name "password" -value $AppPoolIdentity_Pass
- Write-Host "User was configured" -ForegroundColor Green
- Stop-WebSite $iisAppName
- Start-WebSite $iisAppName
- Write-Host "DONE!" -ForegroundColor Red
- Write-Host "Don't forget to move NTLM and set certificate!" -ForegroundColor Yellow
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement