title: How does one configure the authentication of an IIS website (hosting a WCF REST service application) using powershell?
body: <p>I have two IIS websites, namely "accounts.example.com" that was created in Visual Studio 2010 using the ASP.NET MVC 3 Web Application and "api.example.com" created with Visual Studio 2010 using the "WCF REST Service Application". </p>
  
  <p>I created a powershell script to configure the environment. The function to create a website looks as follows:</p>
  
  <pre><code>function create-website([string]$name, [string]$relativePath) {
  
      $physicalPath = Join-Path -Path $scriptPath -ChildPath $relativePath
      $physicalPath = [IO.Path]::GetFullPath( $physicalPath )
  
      # Create an application pool and ensure it is using .NET 4
      New-WebAppPool -Name $name
      Set-ItemProperty IIS:\AppPools\$name managedRuntimeVersion v4.0
  
      # Create Website
      New-WebSite -Name $name -Port 80 -HostHeader $name -PhysicalPath $physicalPath
      # Set the Application Pool
      Set-ItemProperty IIS:\Sites\$name ApplicationPool $name
      Set-ItemProperty IIS:\Sites\$name ApplicationPool $name
  
      # Update Authentication
      Set-WebConfigurationProperty -filter /system.WebServer/security/authentication/AnonymousAuthentication -name enabled -value true -location $name
      Set-WebConfigurationProperty -filter /system.WebServer/security/authentication/windowsAuthentication -name enabled -value false -location $name
      Set-WebConfigurationProperty -filter /system.WebServer/security/authentication/basicAuthentication -name enabled -value false -location $name
  }
  </code></pre>
  
  <p>And its called as follows:</p>
  
  <pre><code>create-website $accounts "..\src\accounts"
  create-website $api "..\src\api\"
  </code></pre>
  
  <p>When I run the script, the accounts website is correctly configured (including authentication). However, when trying to configure the api site, I get the following error:</p>
  
  <pre><code>Set-WebConfigurationProperty : Filename: \\?\S:\example\src\api\web.config
  Line number: 20
  Error: The configuration section 'standardEndpoints' cannot be read because it is missing a section declaration
  At S:\example\scripts\Install-DevelopmentEnvironment.ps1:26 char:33
  +     Set-WebConfigurationProperty &lt;&lt;&lt;&lt;  -filter /system.WebServer/security/authentication/AnonymousAuthentication -name enabled -value true -location $name
      + CategoryInfo          : NotSpecified: (:) [Set-WebConfigurationProperty], COMException
      + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.SetConfigurationPropertyCommand
  </code></pre>
  
  <p>It is unclear to me what could cause this error to begin with since it worked fine on the "accounts" website. Looking at google, some suggested to check if the website is using an application pool running with .NET 4. I verified that the script successfully sets this up.</p>
  
  <p>How should I configure the authentication of an IIS website using Powershell? </p>