We can automate the creation, modification, and deletion of websites in IIS using PowerShell scripts. I want to share some useful scripts to help you save time.
Loading the Web Administration Module
The first step is to load in the PowerShell module for IIS
Import-Module webadministration
Creating a New File or Folder
New-Item is a quick and easy way to create a new file or folder on your computer. As an example, suppose you want to create a new directory named Windows PowerShell within the C:\Scripts folder. To do that call New-Item along with:
1) the full path to the new folder; and,
2) the new item type (which you can specify using the -type parameter and the value directory).
The command in question will look like this for the directory:
New-Item C:\SWTestAcademy -type directory
The command in question will look like this for file:
New-Item c:\SWTestAcademy\onur_test.txt -type file
Creating Web-Sites
New-Item is also used to create new Web-Sites within the IIS PowerShell, you can see Default Web Site below.
Powershell Command:
New-Item iis:\Sites\SWTestAcademySite -bindings @{protocol="http";bindingInformation=":80:SWTestAcademySite"} -physicalPath c:\SWTestAcademy
When you create a Web-Site need some additional parameters like the file system path and network bindings are needed to create a Web-Site.
Creating Web Applications
New-Item 'IIS:\Sites\SWTestAcademySite\SWTestApp' -physicalPath c:\SWTestAcademy -type Application
Specifying the -type parameter you tells the create an application
List Sites
You can get a list of websites running on the server by using the Get-Website cmdlet or by running Get-ChildItem
This is another way to list them
Deleting Sites
Here is how you delete the site using Powershell.
Remove-Item IIS:\Sites\SWTestAcademySite
Thanks,
Onur Yazir

Onur YAZIR is a Senior Software Testing & DevOps Engineer 10+ years of experience. He has worked Huawei, Ericsson, Vodafone, Several FinTech companies, Gulf News, and Emirates Airlines. You can find detailed information about him on his linked-in page.