I just started learning powershell this weekend. I wrote a powershell script to restart an IIS website for a hosted WCF Service when there are too many ‘errant’ connections that need to be cleaned up. Restarting the website in the IIS admin console seems to fix the connection issues. Restarting the WCF Service website in my powershell script does not. I changed the script to stop and start the IIS website when the restart script didn’t do anything. When I run the powershell script I check the state of the IIS website and I see it is stopping and starting. Why is there a difference between restarting a website in the admin console and in a powershell script? Does the admin console do something else I’m not seeing? Also, I put a pause inbetween the stop and start to see if that made a difference. It did not. I’ve included the relevant portion of the script below.
…
if(Get-WebsiteState -Name “$WebsiteName” | Where-Object -Property Value -EQ ‘Started’){
“[$currentDate] Prosperity.ZiivaAdminHost.com found running, stopping and starting it.” | Out-File -FilePath $scriptOutputLog -Append
#stopping and starting website instead of restarting website, since restarting website didn't appear to work
#stopping website
$website = Stop-Website -Name $WebsiteName -Passthru
$siteStateOutput2 = Get-WebsiteState -Name "$WebsiteName"
$output = "[$currentDate] $WebsiteName current state after stopping is: " + $siteStateOutput2."Value"
$output | Out-File -FilePath $scriptOutputLog -Append
<#
Write-Output "stopping..."
Start-Sleep -s 10
Write-Output "starting..."
#>
#starting website
$website | Start-Website
$siteStateOutput3 = Get-WebsiteState -Name "$WebsiteName"
$output = "[$currentDate] $WebsiteName current state after starting is: " + $siteStateOutput3."Value"
$output | Out-File -FilePath $scriptOutputLog -Append
}
…