{"id":174,"date":"2024-09-17T08:55:15","date_gmt":"2024-09-17T13:55:15","guid":{"rendered":"https:\/\/www.calatayud.net\/?p=174"},"modified":"2025-08-16T18:07:55","modified_gmt":"2025-08-16T23:07:55","slug":"web-iis-website-and-app-pool-setup","status":"publish","type":"post","link":"https:\/\/www.calatayud.net\/es\/technology\/programming\/web-iis-website-and-app-pool-setup\/","title":{"rendered":"Web | IIS Website and App Pool Setup"},"content":{"rendered":"<p class=\"wp-block-paragraph\"><strong>Script Summary: <\/strong><br>This PowerShell script automates the configuration of a new IIS (Internet Information Services) website and its associated application pool. It leverages the `WebAdministration` module to streamline setup tasks, ensuring consistency and reducing manual effort. Key operations include:<br><br><strong>Application Pool Configuration<\/strong><br>- Creates a new App Pool named \"MyWebsite Pool\"<br>- Sets idle timeout to 1 hour<br>- Configures daily recycling at 2:00 AM<br>- Assigns a specific user identity for the App Pool (secure password input required)<br><br><strong>Website Deployment<\/strong><br>- Creates the website directory at `D:\\Inetpub\\wwwroot\\MyWebsite\\`<br>- Sets up a new IIS site named **\"mywebsite.com\"** bound to port 80<br>- Associates the site with the newly created App Pool<br><br><strong>IIS Logging Customization<\/strong><br>- Specifies a custom log directory: `D:\\Logs\\IISLogs`<br>- Enables local time rollover for logs<br>- Configures detailed logging fields including client IP, request method, URI, status codes, bytes sent\/received, and more<br><br>This script is ideal for system administrators looking to automate IIS provisioning with tailored performance and logging settings.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>Import-Module \"WebAdministration\"\n\n# Variables for AppPool and Website\n$Var_AppPool='MyWebsite Pool'\n$Var_SitePath='D:\\Inetpub\\wwwroot\\MyWebsite\\'\n$Var_SiteName='mywebsite.com'\n$Var_IISLogsPath='D:\\Logs\\IISLogs'<\/code>\n\n\n<code># Create AppPool\n\nNew-Item IIS:\\AppPools\\$Var_AppPool\n#Set IdleTimeout 60min or 1hr\nSet-ItemProperty -Path IIS:\\AppPools\\$Var_AppPool -Name processModel.idleTimeout -Value (\"01:00:00\")\n#Set Recycling Daily 2am\nSet-ItemProperty -Path IIS:\\AppPools\\$Var_AppPool -Name Recycling.periodicRestart.schedule -Value @{value=\"02:00\"}\n#Set Periodic Recycling Daily 2am\nSet-ItemProperty -Path IIS:\\AppPools\\$Var_AppPool -Name Recycling.periodicRestart -Value \"0\"\n#Set Identity\n#$IdentityUser= $Username + '@' + $AdDomain\n$IdentityPwdTxt = Read-Host -Prompt \"Enter the password AppPool user\" -AsSecureString\n$Identity = @{identitytype=\"SpecificUser\";username=$Netbios_User;password=$IdentityPwdTxt}\nSet-ItemProperty -Path IIS:\\AppPools\\$Var_AppPool -name \"processModel\" -value $Identity\nRestart-WebAppPool -Name $Var_AppPool<\/code>\n\n\n<code># Create Website\n\n#Creates Directories\nNew-Item -Path $Var_SitePath -Type Directory\n#Creates Site\nNew-Item IIS:\\Sites\\$Var_SiteName -physicalPath $Var_SitePath -bindings @{protocol=\"http\";bindingInformation=\":80:\"}\nSet-ItemProperty IIS:\\Sites\\$Var_SiteName -name applicationPool -value $Var_AppPool\n#Assign AppPool to Site\nSet-ItemProperty IIS:\\Sites\\$Var_SiteName -name applicationPool -value $Var_AppPool\n#Set various IIS Logs' properties\n#logfile.directory\nSet-ItemProperty -Path IIS:\\Sites\\$Var_SiteName -Name logfile.directory -Value $Var_IISLogsPath\n#logfile.localTimeRollover\nSet-ItemProperty -Path IIS:\\Sites\\$Var_SiteName -Name logfile.localTimeRollover -Value $True\n#logfile.logExtFileFlags\n$LogAddBytesSentRecv=\"Date,Time,ClientIP,UserName,ServerIP,Method,UriStem,UriQuery,HttpStatus,Win32Status,BytesSent,BytesRecv,TimeTaken,ServerPort,UserAgent,Referer,HttpSubStatus\"\nSet-ItemProperty -Path IIS:\\Sites\\$Var_SiteName -Name logfile.logExtFileFlags -Value $LogAddBytesSentRecv\n#Report all logfile properties\nGet-ItemProperty -Path IIS:\\Sites\\$Var_SiteName -Name logfile<\/code><\/code><\/pre>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>","protected":false},"excerpt":{"rendered":"<p>Script Summary: This PowerShell script automates the configuration of a new IIS (Internet Information Services) website and its associated application pool. It leverages the `WebAdministration` module to streamline setup tasks, ensuring consistency and reducing manual effort. Key operations include: Application Pool Configuration- Creates a new App Pool named \"MyWebsite Pool\"- Sets idle timeout to 1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"","_lightning_design_setting":{"layout":"default"},"footnotes":"[]"},"categories":[13,21],"tags":[29,14],"class_list":["post-174","post","type-post","status-publish","format-standard","hentry","category-programming","category-web","tag-iis","tag-powershell"],"veu_head_title_object":{"title":"","add_site_title":""},"_links":{"self":[{"href":"https:\/\/www.calatayud.net\/es\/wp-json\/wp\/v2\/posts\/174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.calatayud.net\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.calatayud.net\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.calatayud.net\/es\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.calatayud.net\/es\/wp-json\/wp\/v2\/comments?post=174"}],"version-history":[{"count":8,"href":"https:\/\/www.calatayud.net\/es\/wp-json\/wp\/v2\/posts\/174\/revisions"}],"predecessor-version":[{"id":239,"href":"https:\/\/www.calatayud.net\/es\/wp-json\/wp\/v2\/posts\/174\/revisions\/239"}],"wp:attachment":[{"href":"https:\/\/www.calatayud.net\/es\/wp-json\/wp\/v2\/media?parent=174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.calatayud.net\/es\/wp-json\/wp\/v2\/categories?post=174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.calatayud.net\/es\/wp-json\/wp\/v2\/tags?post=174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}