How to compare Microsoft.Exchange.Common.ScheduleInterval with a datetime object?

I want find out if there is any Exchange database schedule running, or will run in the next few hours. However, I couldn't figure out how to compare the scheduleinterval object with a variable I created with get-date or (get-date).addhours(20)

The scheduleInterval I am looking at is

C:\>(get-mailboxdatabase | where {$_.name -like 'database'}).maintenanceschedule  | Get-Member

   TypeName: Microsoft.Exchange.Common.ScheduleInterval

Name         MemberType Definition
----         ---------- ----------
CompareTo    Method     int CompareTo(System.Object value), int CompareTo(Microsoft.Exchange.Common.ScheduleInterval...
ConjointWith Method     bool ConjointWith(Microsoft.Exchange.Common.ScheduleInterval other)
Contains     Method     bool Contains(Microsoft.Exchange.Common.WeekDayAndTime dt), bool Contains(System.DateTime dt...
Equals       Method     bool Equals(System.Object obj)
GetHashCode  Method     int GetHashCode()
GetType      Method     type GetType()
Overlaps     Method     bool Overlaps(Microsoft.Exchange.Common.ScheduleInterval other)
ToString     Method     string ToString()
EndDay       Property   System.DayOfWeek EndDay {get;}
EndHour      Property   System.Int32 EndHour {get;}
EndMinute    Property   System.Int32 EndMinute {get;}
EndTime      Property   Microsoft.Exchange.Common.WeekDayAndTime EndTime {get;}
Length       Property   System.TimeSpan Length {get;}
StartDay     Property   System.DayOfWeek StartDay {get;}
StartHour    Property   System.Int32 StartHour {get;}
StartMinute  Property   System.Int32 StartMinute {get;}
StartTime    Property   Microsoft.Exchange.Common.WeekDayAndTime StartTime {get;}

Any help is much appreciated.

Thanks

Answers


Here a way to test if a job is running at the Get-Date value. Maybe the comparison can be done casting starttime/endtime properties to [datetime] but I can't test, I'm just supposing..

$a = (get-mailboxdatabase | where {$_.name -like 'database'}).maintenanceschedule
$b = Get-date # you can add days to check events in the future
if ( $a.startday, $a.endday -contains $b.dayofweek)
{
  if ( $a.starthour -le $b.hour -and $a.endhour -ge $b.hour)
  {
    if (  $a.startminute -le $b.minute -and $a.endminute -ge $b.minute)
    {
       Write-Host "Jod scheduled is running at this time!"
    }
  }
}

I wrote the following codes to convert the Microsoft.Exchange.Common.ScheduleInterval into an array of datetime objects. Hope someone can improve my codes...

$schedules=(get-mailboxdatabase|where {$_.name -like "dbname"}).maintenanceschedule 

$curdatetime = get-date
$dowhash = @{"Monday"=1;"Tuesday"=2;"Wednesday"=3;"Thursday"=4; `
             "Friday"=5;"Saturday"=6;"Sunday"=7}
$todaydow = $dowhash.get_item([string]$curdatetime.dayofweek)
$coming = @()

foreach ($schedule in $schedules) {
  $dow = $dowhash.get_item([string]$schedule.startday)
  $start = $curdatetime.adddays((($dow+7-$todaydow) % 7))
  $startstr = "{0:yyyyMMdd}{1:00}{2:00}" `
              -f $start,$schedule.starthour,$schedule.startminute

  $dow = $dowhash.get_item([string]$schedule.endday)
  $end = $curdatetime.adddays((($dow+7-$todaydow) % 7))
  $endstr   = "{0:yyyyMMdd}{1:00}{2:00}" `
              -f $end,$schedule.endhour,$schedule.endminute

  $coming+=,([datetime]::ParseExact($startstr,"yyyyMMddHHmm",$null), `
             [datetime]::ParseExact($endstr,"yyyyMMddHHmm",$null) )
}

Thanks


Need Your Help

Assigning retained object to __unsafe_unretained variable , but why don't it crash?

ios iphone automatic-ref-counting

As far as I know str1 is released after assignment. I just receive warning but why don't it crash?

CCK Field, minimum number of values

php drupal cck required

I have created a module which implements a CCK field. When adding the field to a content type, I have set the number of values to unlimited, and set the field to be required.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.