title: Convert IIS Web Application to folder and back
body: <p>I am trying to write a <a href="/questions/tagged/powershell" class="post-tag" title="show questions tagged &#39;powershell&#39;" rel="tag">powershell</a> script that capture the names of all of my IIS Applications and converts them back to folders. Then takes that same set of names and converts them back to Applications. I have a problem with my loop and I believe it has to do with the format of the input variable <code>$AppNames</code></p>
  
  <p>I attempted an <code>$AppNames.ToString()</code> but that didn't work. Any Ideas?</p>
  
  <pre><code>$AppNames1 = Get-Webapplication -Site "Mgmtservice" | Select @{e={$_.Path.Trim('/')};l="Name"} | Format-Table -HideTableHeaders
  $AppNames1
  
  $Site = "MgmtService"
  
  ForEach ($AppName in $AppNames)
  {
    Remove-WebApplication -Name $_ -Site MgmtService
  }
  
  Start-Sleep 6
  
  ForEach ($AppName in $AppNames)
  {
    $Path1 = "IIS:\Sites\Mgmtservice\"
    $Path = $Path1 + $AppName
    ConvertTo-WebApplication -PSPath $Path
  }
  </code></pre>