Cannot create a file when that file already exists. (Exception from HRESULT: 0x 800700B7)

02/11/2012 18:52


Cannot create a file when that file already exists. (Exception from HRESULT: 0x
800700B7)
At C:\cham.TFS\_Tools\flnWebAppScripts\CreateWebApplication.ps1:62 char:
79
+     (get-childitem "IIS:\sites"|where-object {$_.Name -eq $iisSiteName}).Start <<<< ()
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodInvocationException
This error happend when trying to start IIS site, which was already started. Put condition to the code
and start site only when it is stopped.
it was (get-childitem "IIS:\sites"|where-object {$_.Name -eq $iisSiteName}).Start before, the same as $site.Start
   $serverManager = New-Object Microsoft.Web.Administration.ServerManager
    $site = $serverManager.Sites | where { $_.Name -eq $iisSiteName}
    $site.Bindings[0].delete()
    $serverManager.CommitChanges()
    #start running IIS site again if stopped
    if($site.State -eq "Stopped")
    {
        $site.Start()
    }