How do I create a new site in IIS using PowerShell? Print

  • 0

PowerShell is a cross-platform task automation solution consisting of a command-line shell, scripting language, and configuration management framework. It runs on Windows, Linux, and macOS. We can use PowerShell to automate the creation, modification, and deletion of websites in IIS. To create a new website in the IIS through PowerShell, you need to perform the following steps.

  1. Search PowerShell in the Windows Server/Windows system. Once you get the result, right-click on it and select the option Run as administrator to open the application with administrator rights.



  2. Enter the following command in Powershell to load the Web Administration Module.

    Import-Module webadministration





  3. You need to create a folder or file for the website in the drive. New-Item is a quick and easy way to create new files or folders on the system. For example, you create a new directory in C drive i.e., C:\inetpub\nicktest.com.

    New-Item C:\inetpub\nicktest.com -type directory



    You can use the following command to create a file in the drive.

    New-Item C:\inetpub\nicktest.com\index.html -type file






  4. Enter the following command to create a website in the IIS using Powershell. New-Item is also used to create new Websites within the IIS PowerShell.

    New-Item iis:\Sites\nicktest.com -bindings @{protocol="http";bindingInformation=":80:nicktest.com"} -physicalPath C:\inetpub\nicktest.com\



  5. To check whether the website is created or not, enter the following command in Powershell. You can see that the website nicktest.com is created successfully.

    Get-Website





    Let's verify the same website from the IIS

  6. Search IIS (Internet Information Service Manager) in the Windows Server/Windows system and click on it.



  7. Click on the Server name, and then click on the Sites option. You will get the list of websites hosted in the IIS. You can see that the website nicktest.com has been successfully created.



That's all.

 






Was this answer helpful?

« Back

chat