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
SteveCox
Nov 05, 2021Brass Contributor
Hi AndresGorzelany
Thanks for all of your help with this, what I want is to compare this output with todays Data and if it is less than 1 hours difference then continue if more then do something else
Thanks for all of your help with this, what I want is to compare this output with todays Data and if it is less than 1 hours difference then continue if more then do something else
- SteveCoxNov 08, 2021Brass ContributorThanks 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"} - Nov 05, 2021If I understand correctly you want to compare two dates
here you have a good resource https://adamtheautomator.com/powershell-get-date/