Advertisement
Guest User

CreateSiteForApp.ps1

a guest
Jun 19th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Set Parameters:
  2. $iisAppPoolName = "LSIntranet"
  3. $hostHeader = "" #without protocol, leave empty if neccessary
  4. $port = "4432" #set port (even if 443)
  5.  
  6. $PipelineMode = "Integrated" # Integrated/Classic
  7. $AppPoolIdentity_Name = "<<Login>>"
  8. $AppPoolIdentity_Pass = '<<Password>>'
  9.  
  10.  
  11. $iisAppPoolDotNetVersion = "v4.0"
  12.  
  13. #-------------------------------------
  14.  
  15.  
  16. $iisAppName = $iisAppPoolName
  17. $directoryPath = "C:\inetpub\wwwroot\" + $iisAppName
  18.  
  19.  
  20. Import-Module WebAdministration
  21.  
  22.  
  23. #navigate to the app pools root
  24. cd IIS:\AppPools\
  25.  
  26. #check if the app pool exists
  27. if (!(Test-Path $iisAppPoolName -pathType container))
  28. {
  29.     #create the app pool
  30.     $appPool = New-Item $iisAppPoolName
  31.     $appPool | Set-ItemProperty -Name "managedRuntimeVersion" -Value $iisAppPoolDotNetVersion
  32.     $appPool.ManagedPipelineMode = $PipelineMode
  33.  
  34.     Write-Host "Application Pool was created." -ForegroundColor Green
  35.    
  36.     #set application pool identity
  37.     $appPool.processModel.username = $AppPoolIdentity_Name
  38.     $appPool.processModel.password = $AppPoolIdentity_Pass
  39.     $appPool.processModel.identityType = 3
  40.     $appPool | set-item
  41.    
  42.     Restart-WebAppPool $iisAppPoolName
  43.     Write-Host "Application Pool was configured." -ForegroundColor Green
  44. }
  45.  
  46.  
  47.  
  48.  
  49.  
  50. #navigate to the sites root
  51. cd IIS:\Sites\
  52.  
  53. #check if the site exists
  54. if (Test-Path $iisAppName -pathType container)
  55. {
  56.     return
  57. }
  58.  
  59.  
  60.  
  61.  
  62. #create the site
  63. New-item -Path $directoryPath -ItemType Directory
  64.  
  65.  
  66. if ($hostHeader) {
  67.     $iisApp = New-WebSite $iisAppName -physicalPath $directoryPath -ApplicationPool $iisAppPoolName -Ssl -Port $port -HostHeader $hostHeader
  68. }
  69. else {
  70.     $iisApp = New-WebSite $iisAppName -physicalPath $directoryPath -ApplicationPool $iisAppPoolName -Ssl -Port $port
  71. }
  72.  
  73.  
  74. Write-Host "Web site was created" -ForegroundColor Green
  75. Write-Host "Binding was configured" -ForegroundColor Green
  76.  
  77.  
  78. #Enable Windows auth
  79. Set-WebConfigurationProperty -filter "/system.webServer/security/authentication/windowsAuthentication" -name enabled -value true -PSPath "IIS:\" -location $iisAppName
  80.  
  81.  
  82.  
  83. Write-Host "Windows Authentication was enabled" -ForegroundColor Green
  84.  
  85. #Set "Connect As"
  86. Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/site[@name='$iisAppName']/application[@path='/']/virtualDirectory[@path='/']" -name "userName" -value $AppPoolIdentity_Name
  87. Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/site[@name='$iisAppName']/application[@path='/']/virtualDirectory[@path='/']" -name "password" -value $AppPoolIdentity_Pass
  88.  
  89. Write-Host "User was configured" -ForegroundColor Green
  90.  
  91. Stop-WebSite $iisAppName
  92. Start-WebSite $iisAppName
  93.  
  94. Write-Host "DONE!" -ForegroundColor Red
  95. Write-Host "Don't forget to move NTLM and set certificate!" -ForegroundColor Yellow
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement