Last active
April 13, 2018 08:20
-
-
Save Bigtalljosh/b9e58aed32023c1793ea802fd426269f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Try and get the processes to kill, we silently ignore any errors because sometimes one of them isn't running | |
# Note: this line doesn't need to be in the try, because if it errors we're ignoring it. | |
$ProcessesToKill = Get-Process -Name 'xxxxx', 'xxxxx' -ErrorAction SilentlyContinue | |
Try | |
{ | |
# Try to kill the processess we were able to get | |
Stop-Process $ProcessesToKill -Force | |
# Stop all sites on IIS | |
get-childitem -path IIS:Sites | foreach { stop-website $_.Name; } | |
# Pause for 1 second | |
Start-Sleep -s 1 | |
# Start all sites on IIS | |
get-childitem -path IIS:Sites | foreach { start-website $_.Name; } | |
} | |
Catch | |
{ | |
# If we got an error for whatever reason, let us know about it. | |
$ErrorMessage = $_.Exception.Message | |
$FailedItem = $_.Exception.ItemName | |
Send-MailMessage -From fromemail -To toemail -Subject "TNI reset issues" -SmtpServer EXCH01.AD.MyCompany.Com -Body "We failed to kill process $FailedItem. The error message was $ErrorMessage" | |
Break | |
} | |
finally | |
{ | |
# This will print out to the console a list of sites running on IIS and their bindings. | |
Get-WebBinding | % { | |
$name = $_.ItemXPath -replace '(?:.*?)name=''([^'']*)(?:.*)', '$1' | |
New-Object psobject -Property @{ | |
Name = $name | |
Binding = $_.bindinginformation.Split(":")[-1] | |
} | |
} | Group-Object -Property Name | | |
Format-Table Name, @{n="Bindings";e={$_.Group.Binding -join "`n"}} -Wrap | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment