Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $hour = Get-Date -Format HH
- $minute = Get-Date -Format mm
- #no need to check mail before 8a.m. and after 6 p.m. office hours
- #execute on every 30 mins
- if( (($hour -ge 8) -or ($hour -le 18)) -and (( ($minute -eq 00) -or ($minute -eq 01) ) -or ($minute -eq 30)) )
- {
- $ie = New-Object -ComObject InternetExplorer.Application
- $ie.Visible = $true
- $url = "https://myMailUrl.com/?Login"
- $ie.Navigate($url)
- Start-Sleep -Seconds 10
- $doc = $ie.Document
- $counter = 0
- #logic to retry 5 times
- while($doc -eq $null)
- {
- $ie.quit()
- $counter = $counter + 1
- ipconfig /flushdns
- Start-Sleep -Seconds 2
- netsh interface set interface “Local Area Connection DISABLE
- Start-Sleep 3
- netsh interface set interface “Local Area Connection ENABLE
- $ie = $null
- $ie = New-Object -ComObject InternetExplorer.Application
- $ie.Navigate($url)
- $doc = $ie.Document
- if($counter -eq 5)
- {
- [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
- [System.Windows.Forms.MessageBox]::Show("Error! Maybe Connection problems.")
- break
- }
- Start-Sleep -Seconds 2
- }
- $usernameInput = $doc.getElementsByName("Username")
- $passInput = $doc.getElementsByName("Password")
- foreach($p in $passInput) {$p.value = "myPass"}
- $loginBtn = $doc.getElementsByTagName("input")
- foreach($i in $loginBtn) { if($i.Type -eq "submit") {$i.click()} }
- Start-Sleep -Seconds 2
- $doc = $null
- Start-Sleep -Seconds 25
- $doc = $ie.Document
- $spans = $doc.getElementsByTagName("span")
- foreach($s in $spans) { if($s.InnerText -eq "Mail") {$s.click()} }
- Start-Sleep -Seconds 2
- $doc = $null
- $doc = $ie.Document
- $refresh = $doc.getElementsByTagName("img")
- #refresh IN-mailbox
- foreach($i in $refresh) { if($i.Title -match "Click to refresh the current view") {$i.click()} }
- Start-Sleep -Seconds 3
- $newMail = $false
- foreach($i in $refresh)
- {
- #active only if new inbox mails
- if($i.Title -match "Unread message ")
- {
- $ie.Visible = $true
- $newMail = $true
- }
- }
- if($newMail -ne $true)
- {
- $ie.Quit()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement