title: "Cannot create a file" error when running Start-Website command in Powershell
body: <p>Currently I'm trying to run this powershell script:</p>
  
  <pre><code>Param (
      $websiteName,
      $physicalPath
  )
  
  import-module WebAdministration
  $website = get-website | where-object { $_.name -eq "$websiteName" }
  if($website -eq $null){
      New-webapppool -Name "$websiteName"
      Set-WebConfiguration -filter "/system.applicationHost/applicationPools/add[@name='$websiteName']" -PSPath IIS:\ -value (@{managedRuntimeVersion="v4.0"})
      New-website -Name "$websiteName" -PhysicalPath "$physicalPath" -ApplicationPool "$websiteName"
      start-website "$websiteName"
  }
  </code></pre>
  
  <p>I use the following command to run the script:  </p>
  
  <pre><code>&amp; .\InstallWebsite.ps1 -websiteName "MyWebsite" -physicalPath "C:\TEST\MyWebsite"
  </code></pre>
  
  <p>Everything works fine, except for the last command inside of the if statement:</p>
  
  <pre><code>start-website "$websiteName"
  </code></pre>
  
  <p>When that command runs, I receive the following error, which I haven't been able to successfully troubleshoot:</p>
  
  <pre><code>Start-Website : Cannot create a file when that file already exists. (Exception from HRESULT: 0x800700B7)
  At line:1 char:14
  + start-website &lt;&lt;&lt;&lt;  "MyWebsite"
      + CategoryInfo          : InvalidOperation: (:) [Start-Website], COMException
      + FullyQualifiedErrorId : InvalidOperation,Microsoft.IIs.PowerShell.Provider.StartWebsiteCommand
  </code></pre>
  
  <p>I also have the following script to remove the website if it matters:</p>
  
  <pre><code>Param (
      $websiteName,
      $appPoolName
  )
  
  import-module WebAdministration
  $website = get-website | where-object { $_.name -eq "$websiteName" }
  if($website -ne $null){
      remove-website -Name "$websiteName"
      remove-webapppool -Name "$websiteName"
  }
  </code></pre>
  
  <p>I run it with the following command:</p>
  
  <pre><code>&amp; .\UninstallWebsite.ps1 -websiteName "MyWebsite" -appPoolname "MyWebsite"
  </code></pre>