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...
SteveCox
Nov 05, 2021Brass Contributor
Just got one more question and then I can complete this bit of work and post it here. I need to get the last modified date from an Invoke-WebRequest
$response = Invoke-WebRequest -uri http://xxxxxxx
and if I look at $response I get the following output
"PS C:\Windows\system32> $response1
StatusCode : 200
StatusDescription : OK
Content : ÿþ< ! D O C T Y P E h t m l P U B L I C
" - / / W 3 C / / D T D X H T M L 1 . 0
S t r i c t / / E N " " h t t p : / / w w w . w 3 . o r g / T
R / x h t m l 1 / D T D / x h t m l 1 - s ...
RawContent : HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 2414
Content-Type: text/html
Date: Thu, 04 Nov 2021 16:55:02 GMT
ETag: "40fb6e89bd1d71:0"
Last-Modified: Thu, 04 Nov 2021 16:49:17 GMT
Serve...
Forms : {}
Headers : {[Accept-Ranges, bytes], [Content-Length, 2414], [Content-Type,
text/html], [Date, Thu, 04 Nov 2021 16:55:02 GMT]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : System.__ComObject
RawContentLength : 2414"
What I need is to get the Last-Modified date and check that this is todays date but cannot find a way to do this?
$response = Invoke-WebRequest -uri http://xxxxxxx
and if I look at $response I get the following output
"PS C:\Windows\system32> $response1
StatusCode : 200
StatusDescription : OK
Content : ÿþ< ! D O C T Y P E h t m l P U B L I C
" - / / W 3 C / / D T D X H T M L 1 . 0
S t r i c t / / E N " " h t t p : / / w w w . w 3 . o r g / T
R / x h t m l 1 / D T D / x h t m l 1 - s ...
RawContent : HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 2414
Content-Type: text/html
Date: Thu, 04 Nov 2021 16:55:02 GMT
ETag: "40fb6e89bd1d71:0"
Last-Modified: Thu, 04 Nov 2021 16:49:17 GMT
Serve...
Forms : {}
Headers : {[Accept-Ranges, bytes], [Content-Length, 2414], [Content-Type,
text/html], [Date, Thu, 04 Nov 2021 16:55:02 GMT]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : System.__ComObject
RawContentLength : 2414"
What I need is to get the Last-Modified date and check that this is todays date but cannot find a way to do this?
Nov 05, 2021
- 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/ - SteveCoxNov 05, 2021Brass ContributorHi 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