Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

This might work, but please let me know what would be the real way to do this?

$
0
0
# For any given "Morning Action Time" this script might test whether the current time is
# within a set number of minutes--$MinutesTimeInterval--before or after the current time
# Use: in a larger script that is fired by Task Scheduler at 10 minute intervals all day
# Once per morning, at a set "Morning Action Time", the script can fire other actions, 
# e.g., send an email or something
$Now=Get-Date
[INT]$MinutesTimeInterval= 5
$MorningActionTime='14:50'
$CurrentDiff = New-TimeSpan $Now $MorningActionTime
[INT]$AbsCurrentDiff = $CurrentDiff.TotalMinutes
#Write-Host 'Time of Day is ' $Now.TimeOfDay
#Write-Host 'Difference-in Minutes-between Now and MorningSendTime is: ' $AbsCurrentDiff
IF ($AbsCurrentDiff -lt 0) {$AbsCurrentDiff *=-1 } # Is there an easier way to return Absolute Value?
IF ($AbsCurrentDiff -le $MinutesTimeInterval)
  {Write-Host Within 5 minutes, either way, of Morning Send Time so...Do some stuff}
ELSE #IF (-not($AbsCurrentDiff -le $MinutesTimeInterval))
  {Write-Host Farther than 5 minutes away, either way, from Morning Send Time so... Do nothing}
Just began fooling with PowerShell last week and, as I am probably demonstating here, I don't know the language very well yet.  Would someone be kind enought to shread this up as needed and let me know how to make it a little cleaner/prettier?

HomeCookN


Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>