Forum Discussion
SteveCox
Oct 11, 2021Brass Contributor
Automation of Exchange server Patching
Hi I am trying to setup a Script to automate patching of Exchange 2016 servers and I need to get the script to check if any if the other exchange server is in Maintenance Mode before continuing to pl...
Nov 05, 2021
If I understand correctly you want to compare two dates
here you have a good resource https://adamtheautomator.com/powershell-get-date/
here you have a good resource https://adamtheautomator.com/powershell-get-date/
SteveCox
Nov 08, 2021Brass Contributor
Thanks got this to work for me by doing the below
#Check that the HTML source was Created less that one hour ago
function httpfiledate {
$response2=Invoke-WebRequest "http://xxxxxxxx/edgestatus/"
$response2.Headers.GetEnumerator() | ForEach {
If($_.Key -eq "Last-Modified" )
{
$_.value}
$dateString={string]$_.value
$dateObject= get-date $dateString
}
}
}
$filedate = httpfiledate
$FileDateObj = get-date $filedate
$hours = -1
$dif = (($FileDateObj) - (Get-Date).AddHours($hours))
if ($dif.Hours -ne 0) {Send-MailMessage -to $mailRecip -From $mailSender -Subject $mailSubject1 -BodyAsHtml -SmtpServer $mailServer -Body "HTTP File on Edge2 is over 1 hour old check Shed Task" ; Break }
Else {Write-host "File OK"}
#Check that the HTML source was Created less that one hour ago
function httpfiledate {
$response2=Invoke-WebRequest "http://xxxxxxxx/edgestatus/"
$response2.Headers.GetEnumerator() | ForEach {
If($_.Key -eq "Last-Modified" )
{
$_.value}
$dateString={string]$_.value
$dateObject= get-date $dateString
}
}
}
$filedate = httpfiledate
$FileDateObj = get-date $filedate
$hours = -1
$dif = (($FileDateObj) - (Get-Date).AddHours($hours))
if ($dif.Hours -ne 0) {Send-MailMessage -to $mailRecip -From $mailSender -Subject $mailSubject1 -BodyAsHtml -SmtpServer $mailServer -Body "HTTP File on Edge2 is over 1 hour old check Shed Task" ; Break }
Else {Write-host "File OK"}