{"componentChunkName":"component---src-templates-articles-index-jsx","path":"/articles/powershell-manage-iis-websites/","result":{"data":{"props":{"adsense":true,"adsenseMobile":null,"byLine":"","canonical":"https://www.business.com/articles/powershell-manage-iis-websites/","content":"<p>When setting up a new website in IIS are you still using the IIS Web Manager? If so, here's a much more scalable, reliable and faster way.</p>\n<p>By using the <strong>WebAdminstration</strong> module and the <strong>Invoke-Command</strong> cmdlet in PowerShell you can just as easily manage 1, 100 or 1,000 different websites on an IIS server. Let's see how we can make this a reality.</p>\r\n<h2>First steps</h2>\r\n<p>First, you'll need to ensure you've got IIS installed on your Windows Server. We'll be demonstrating these steps on a Windows Server 2012 R2 machine, but this should work the same on Windows Server 2008 R2 as well.</p>\r\n<p>Next, you'll need to ensure you've got PowerShell remoting configured and the appropriate firewall ports allowed on the server. The quickest way to do to this is by running <strong>winrm quickconfig</strong> on the server. This will go through all of the prerequisite steps to make PowerShell remoting available.</p>\r\n<p>When IIS is installed, it comes with a PowerShell module called <strong>WebAdministration</strong>. This module gives you many different cmdlets for managing IIS. You can see we've got six cmdlets specifically dedicated to managing websites.</p>\r\n<p><picture class=\"aligncenter full\"><source srcset=\"/images/content/5b6/d12251039ebf4508b4582/1200_-240- 1200w, /images/content/5b6/d12251039ebf4508b4582/668_-134- 668w, /images/content/5b6/d12251039ebf4508b4582/320_-64- 320w\" sizes=\"668px, 100%\"></source><img src=\"/images/content/5b6/d12251039ebf4508b4582/892-179-\" alt=\"\" width=\"892\" height=\"179\" data-content-img-id=\"5b6d12251039ebf4508b4582\"></picture></p>\r\n<p>Let's see if we have any websites on our IIS server.</p>\r\n<blockquote>Get-Website</blockquote>\r\n<p><picture class=\"aligncenter full\"><source srcset=\"/images/content/5b6/d126d51ee4740518b457e/1200_-241- 1200w, /images/content/5b6/d126d51ee4740518b457e/668_-134- 668w, /images/content/5b6/d126d51ee4740518b457e/320_-64- 320w\" sizes=\"668px, 100%\"></source><img src=\"/images/content/5b6/d126d51ee4740518b457e/775-156-\" alt=\"\" width=\"775\" height=\"156\" data-content-img-id=\"5b6d126d51ee4740518b457e\"></picture></p>\r\n<p>It looks like we have the default website as well as a couple other site for our PowerShell Desired State Configuration setup. We'd like to create another one for a web application we're building. We'll first need to create a folder, then use the <strong>New-WebSite</strong> cmdlet to specify a name for the website and where to place it on the filesystem. Notice, by default, it creates the website as stopped and sets a HTTP binding on port 80.</p>\r\n<blockquote>New-Website –Name MyWebApp –PhysicalPath C:\\inetpub\\MyWebApp</blockquote>\r\n<p><picture class=\"aligncenter full\"><source srcset=\"/images/content/5b6/d12b41039ebf5508b457b/1200_-438- 1200w, /images/content/5b6/d12b41039ebf5508b457b/668_-243- 668w, /images/content/5b6/d12b41039ebf5508b457b/320_-116- 320w\" sizes=\"668px, 100%\"></source><img src=\"/images/content/5b6/d12b41039ebf5508b457b/753-275-\" alt=\"\" width=\"753\" height=\"275\" data-content-img-id=\"5b6d12b41039ebf5508b457b\"></picture></p>\r\n<p>Since I want to use this website, we'll need to start it.</p>\r\n<blockquote>Get-Website –Name MyWebApp | Start-Website</blockquote>\r\n<p><picture class=\"aligncenter full\"><source srcset=\"/images/content/5b6/d131251ee4750518b457d/1200_-146- 1200w, /images/content/5b6/d131251ee4750518b457d/668_-81- 668w, /images/content/5b6/d131251ee4750518b457d/320_-39- 320w\" sizes=\"668px, 100%\"></source><img src=\"/images/content/5b6/d131251ee4750518b457d/1048-128-\" alt=\"\" width=\"1048\" height=\"128\" data-content-img-id=\"5b6d131251ee4750518b457d\"></picture></p>\r\n<p>Oops! We got an error. This error means that we have a conflicting binding. Let's see which website is doing that. Recall that it was creating the site with a HTTP binding on port 80.</p>\r\n<blockquote>Get-Website | <br>            Where {($_.bindings.collection.protocol –eq ‘http’) –and <br>                        ($_.bindings.collection.bindingInfo –eq ‘*:80:’)<br>}<br><br>\n</blockquote>\r\n<p><picture class=\"aligncenter full\"><source srcset=\"/images/content/5b6/d133851ee472f518b4584/1200_-133- 1200w, /images/content/5b6/d133851ee472f518b4584/668_-74- 668w, /images/content/5b6/d133851ee472f518b4584/320_-35- 320w\" sizes=\"668px, 100%\"></source><img src=\"/images/content/5b6/d133851ee472f518b4584/1132-126-\" alt=\"\" width=\"1132\" height=\"126\" data-content-img-id=\"5b6d133851ee472f518b4584\"></picture></p>\r\n<p>It looks like the Default Website is using the same binding. Let's stop the default website.</p>\r\n<blockquote>Get-Website –Name ‘Default Web Site’ | Stop-Website<br><br>\n</blockquote>\r\n<p>Now, let's try to start up our MyWebApp website again. You'll see that you no longer receive that error message. We now have a website called MyWebApp started up and ready to go.</p>\r\n<h2>PowerShell IIS Drive</h2>\r\n<p>By now you've seen how to use the cmdlets to manage websites but we haven't talked about another useful feature that comes with the <strong>WebAdministration</strong> module called the PowerShell IIS drive. When you import the <strong>WebAdministration</strong> module, PowerShell builds a drive called IIS. This drive allows you to manage IIS just like you would via the file system by simply using <strong>IIS: </strong>instead of <strong>C:</strong> to represent the drive.</p>\r\n<p>To demonstrate this drive, instead of using <strong>Remove-Website</strong> to remove this website let's simply use <strong>Remove-Item</strong> and the IIS drive.</p>\r\n<p><picture class=\"aligncenter full\"><source srcset=\"/images/content/5b6/d136451ee472f518b4586/1200_-427- 1200w, /images/content/5b6/d136451ee472f518b4586/668_-237- 668w, /images/content/5b6/d136451ee472f518b4586/320_-113- 320w\" sizes=\"668px, 100%\"></source><img src=\"/images/content/5b6/d136451ee472f518b4586/772-275-\" alt=\"\" width=\"772\" height=\"275\" data-content-img-id=\"5b6d136451ee472f518b4586\"></picture></p>\r\n<p>You can see that the IIS drive makes removing a website just as easy as removing a file! The IIS drive is a handy way to manage lots of different configuration items in IIS.</p>\r\n<p>You've seen that managing websites is very easy with PowerShell. We were working on a single server but by applying the techniques you learned in this article, you can now replicate this on many servers at once. For example, maybe you'd like to create a website called <strong>MyWebApp</strong> on a list of servers in a text file. No problem!</p>\r\n<blockquote>Get-Content –Path ‘C:\\Servers.txt’ | Invoke-Command –ScriptBlock {<br>    Import-Module WebAdministration<br>    New-Website –Name MyWebApp –PhysicalPath <br>C:\\inetpub\\MyWebApp<br>    }</blockquote>\r\n<p>All it takes is to read each server name in a text file, take our existing code to build a website and place that into a script block which we then pass to the <strong>Invoke-Command</strong> cmdlet to run it remotely on each server.</p>\r\n<p>The next time you launch the IIS manager think to yourself, \"Can I do this in PowerShell?\" If you can, do it. It will save you tons of time!</p>\n","docType":"article","guid":"articles_50dced10b66cbfb141e60ef667844b0e","lastModified":"2018-09-06T07:00:00.000Z","published":"2018-09-06T07:00:00.000Z","structuredData":null,"subtitle":"When setting up a new website in IIS are you still using the IIS Web Manager?","template":"v1","title":"How To Manage IIS Websites With PowerShell","type":"article","author":{"avatar":null,"bio":"Adam Bertram is a 20-year veteran of IT and experienced online business professional. He's an entrepreneur, IT influencer, Microsoft MVP, blogger, trainer and content marketing writer for multiple technology companies. Adam is also the founder of the popular IT career development platform TechSnips. Catch up on Adam's articles at adamtheautomator.com, connect on LinkedIn, or follow him on Twitter at @adbertram or the TechSnips Twitter account at @techsnips_io.","name":"Adam Bertram","image":null,"slug":null,"social":{"facebook":"","linkedin":"https://www.linkedin.com/in/adambertram/","twitter":"https://twitter.com/adbertram","website":"https://www.adamtheautomator.com/"},"status":"enabled","title":null,"type":"Contributing Writer","user":{"imagePath":"https://www.business.com/images/undefined","profile":{"company":"eGain Communications","jobTitle":"Product Management Analyst","website":""}}},"breadcrumbs":null,"channels":{"primary":{"name":"Marketing","slug":"marketing"},"sub":{"name":"Marketing Solutions","slug":"marketing-solutions"}},"meta":{"robots":"index, follow","description":"When setting up a new website in IIS are you still using the IIS Web Manager? If so, here's a much more scalable, reliable and faster way.","title":"Manage IIS Websites With PowerShell - business.com"},"parsedContent":{"toc":[{"id":"first-steps","title":"First steps"},{"id":"powershell-iis-drive","title":"PowerShell IIS Drive"}],"json":[{"component":"p","children":["When setting up a new website in IIS are you still using the IIS Web Manager? If so, here's a much more scalable, reliable and faster way."]},{"component":"p","children":["By using the ",{"component":"strong","children":["WebAdminstration"]}," module and the ",{"component":"strong","children":["Invoke-Command"]}," cmdlet in PowerShell you can just as easily manage 1, 100 or 1,000 different websites on an IIS server. Let's see how we can make this a reality."]},{"component":"h2","props":{"id":"first-steps"},"children":["First steps"]},{"component":"p","children":["First, you'll need to ensure you've got IIS installed on your Windows Server. We'll be demonstrating these steps on a Windows Server 2012 R2 machine, but this should work the same on Windows Server 2008 R2 as well."]},{"component":"p","children":["Next, you'll need to ensure you've got PowerShell remoting configured and the appropriate firewall ports allowed on the server. The quickest way to do to this is by running ",{"component":"strong","children":["winrm quickconfig"]}," on the server. This will go through all of the prerequisite steps to make PowerShell remoting available."]},{"component":"p","children":["When IIS is installed, it comes with a PowerShell module called ",{"component":"strong","children":["WebAdministration"]},". This module gives you many different cmdlets for managing IIS. You can see we've got six cmdlets specifically dedicated to managing websites."]},{"component":"p","children":[{"component":"picture","props":{"className":"aligncenter full"},"children":[{"component":"source","props":{"srcSet":"/images/content/5b6/d12251039ebf4508b4582/1200_-240- 1200w, /images/content/5b6/d12251039ebf4508b4582/668_-134- 668w, /images/content/5b6/d12251039ebf4508b4582/320_-64- 320w","sizes":"668px, 100%"}},{"component":"img","props":{"src":"/images/content/5b6/d12251039ebf4508b4582/892-179-","alt":"","width":"892","height":"179","data-content-img-id":"5b6d12251039ebf4508b4582"}}]}]},{"component":"p","children":["Let's see if we have any websites on our IIS server."]},{"component":"blockquote","children":["Get-Website"]},{"component":"p","children":[{"component":"picture","props":{"className":"aligncenter full"},"children":[{"component":"source","props":{"srcSet":"/images/content/5b6/d126d51ee4740518b457e/1200_-241- 1200w, /images/content/5b6/d126d51ee4740518b457e/668_-134- 668w, /images/content/5b6/d126d51ee4740518b457e/320_-64- 320w","sizes":"668px, 100%"}},{"component":"img","props":{"src":"/images/content/5b6/d126d51ee4740518b457e/775-156-","alt":"","width":"775","height":"156","data-content-img-id":"5b6d126d51ee4740518b457e"}}]}]},{"component":"p","children":["It looks like we have the default website as well as a couple other site for our PowerShell Desired State Configuration setup. We'd like to create another one for a web application we're building. We'll first need to create a folder, then use the ",{"component":"strong","children":["New-WebSite"]}," cmdlet to specify a name for the website and where to place it on the filesystem. Notice, by default, it creates the website as stopped and sets a HTTP binding on port 80."]},{"component":"blockquote","children":["New-Website –Name MyWebApp –PhysicalPath C:\\inetpub\\MyWebApp"]},{"component":"p","children":[{"component":"picture","props":{"className":"aligncenter full"},"children":[{"component":"source","props":{"srcSet":"/images/content/5b6/d12b41039ebf5508b457b/1200_-438- 1200w, /images/content/5b6/d12b41039ebf5508b457b/668_-243- 668w, /images/content/5b6/d12b41039ebf5508b457b/320_-116- 320w","sizes":"668px, 100%"}},{"component":"img","props":{"src":"/images/content/5b6/d12b41039ebf5508b457b/753-275-","alt":"","width":"753","height":"275","data-content-img-id":"5b6d12b41039ebf5508b457b"}}]}]},{"component":"p","children":["Since I want to use this website, we'll need to start it."]},{"component":"blockquote","children":["Get-Website –Name MyWebApp | Start-Website"]},{"component":"p","children":[{"component":"picture","props":{"className":"aligncenter full"},"children":[{"component":"source","props":{"srcSet":"/images/content/5b6/d131251ee4750518b457d/1200_-146- 1200w, /images/content/5b6/d131251ee4750518b457d/668_-81- 668w, /images/content/5b6/d131251ee4750518b457d/320_-39- 320w","sizes":"668px, 100%"}},{"component":"img","props":{"src":"/images/content/5b6/d131251ee4750518b457d/1048-128-","alt":"","width":"1048","height":"128","data-content-img-id":"5b6d131251ee4750518b457d"}}]}]},{"component":"p","children":["Oops! We got an error. This error means that we have a conflicting binding. Let's see which website is doing that. Recall that it was creating the site with a HTTP binding on port 80."]},{"component":"blockquote","children":["Get-Website | ",{"component":"br"},"            Where {($_.bindings.collection.protocol –eq ‘http’) –and ",{"component":"br"},"                        ($_.bindings.collection.bindingInfo –eq ‘*:80:’)",{"component":"br"},"}",{"component":"br"},{"component":"br"}]},{"component":"p","children":[{"component":"picture","props":{"className":"aligncenter full"},"children":[{"component":"source","props":{"srcSet":"/images/content/5b6/d133851ee472f518b4584/1200_-133- 1200w, /images/content/5b6/d133851ee472f518b4584/668_-74- 668w, /images/content/5b6/d133851ee472f518b4584/320_-35- 320w","sizes":"668px, 100%"}},{"component":"img","props":{"src":"/images/content/5b6/d133851ee472f518b4584/1132-126-","alt":"","width":"1132","height":"126","data-content-img-id":"5b6d133851ee472f518b4584"}}]}]},{"component":"p","children":["It looks like the Default Website is using the same binding. Let's stop the default website."]},{"component":"blockquote","children":["Get-Website –Name ‘Default Web Site’ | Stop-Website",{"component":"br"},{"component":"br"}]},{"component":"p","children":["Now, let's try to start up our MyWebApp website again. You'll see that you no longer receive that error message. We now have a website called MyWebApp started up and ready to go."]},{"component":"h2","props":{"id":"powershell-iis-drive"},"children":["PowerShell IIS Drive"]},{"component":"p","children":["By now you've seen how to use the cmdlets to manage websites but we haven't talked about another useful feature that comes with the ",{"component":"strong","children":["WebAdministration"]}," module called the PowerShell IIS drive. When you import the ",{"component":"strong","children":["WebAdministration"]}," module, PowerShell builds a drive called IIS. This drive allows you to manage IIS just like you would via the file system by simply using ",{"component":"strong","children":["IIS: "]},"instead of ",{"component":"strong","children":["C:"]}," to represent the drive."]},{"component":"p","children":["To demonstrate this drive, instead of using ",{"component":"strong","children":["Remove-Website"]}," to remove this website let's simply use ",{"component":"strong","children":["Remove-Item"]}," and the IIS drive."]},{"component":"p","children":[{"component":"picture","props":{"className":"aligncenter full"},"children":[{"component":"source","props":{"srcSet":"/images/content/5b6/d136451ee472f518b4586/1200_-427- 1200w, /images/content/5b6/d136451ee472f518b4586/668_-237- 668w, /images/content/5b6/d136451ee472f518b4586/320_-113- 320w","sizes":"668px, 100%"}},{"component":"img","props":{"src":"/images/content/5b6/d136451ee472f518b4586/772-275-","alt":"","width":"772","height":"275","data-content-img-id":"5b6d136451ee472f518b4586"}}]}]},{"component":"p","children":["You can see that the IIS drive makes removing a website just as easy as removing a file! The IIS drive is a handy way to manage lots of different configuration items in IIS."]},{"component":"p","children":["You've seen that managing websites is very easy with PowerShell. We were working on a single server but by applying the techniques you learned in this article, you can now replicate this on many servers at once. For example, maybe you'd like to create a website called ",{"component":"strong","children":["MyWebApp"]}," on a list of servers in a text file. No problem!"]},{"component":"blockquote","children":["Get-Content –Path ‘C:\\Servers.txt’ | Invoke-Command –ScriptBlock {",{"component":"br"},"    Import-Module WebAdministration",{"component":"br"},"    New-Website –Name MyWebApp –PhysicalPath ",{"component":"br"},"C:\\inetpub\\MyWebApp",{"component":"br"},"    }"]},{"component":"p","children":["All it takes is to read each server name in a text file, take our existing code to build a website and place that into a script block which we then pass to the ",{"component":"strong","children":["Invoke-Command"]}," cmdlet to run it remotely on each server."]},{"component":"p","children":["The next time you launch the IIS manager think to yourself, \"Can I do this in PowerShell?\" If you can, do it. It will save you tons of time!"]}]},"resource":null,"sponsorship":null,"thumbnail":{"path":"https://www.business.com/images/content/5d0/07b2b7b437409688b4568/1500-0-","caption":"kikujungboy/Shutterstock","isBlurred":false},"bestPicks":null},"related":null},"pageContext":{"displayModified":"2018-09-06T07:00:00.000Z","template":"v1","title":"How To Manage IIS Websites With PowerShell","meta":{"robots":"index, follow"},"docType":"articles","slug":"powershell-manage-iis-websites","canonical":"https://www.business.com/articles/powershell-manage-iis-websites/","skipTOC":false}},"staticQueryHashes":[]}