title: Powershell script to create website in IIS
body: <p>Can someone help me with creation of website from power shell.Script i have written below is not working .</p>
  
  <pre><code>Import-Module WebAdministration
  
  #navigate to the app pools root
  cd IIS:\AppPools\
  
  #check if the app pool exists
  if (!(Test-Path $iisAppPoolName -pathType container))
  {
      #create the app pool
      $appPool = New-Item $iisAppPoolName
      $appPool | Set-ItemProperty -Name "managedRuntimeVersion" -Value $iisAppPoolDotNetVersion
  }
  
  #navigate to the sites root
  cd IIS:\Sites\
  
  #check if the site exists
  if (Test-Path $iisAppName -pathType container)
  {
      return
  }
  
  #create the site
  $iisApp = New-Item $iisAppName -bindings @{protocol="http";bindingInformation=":80:" + $iisAppName} -physicalPath $directoryPath
  $iisApp | Set-ItemProperty -Name "applicationPool" -Value $iisAppPoolName
  </code></pre>