0

我想知道是否有任何 Exchange 数据库计划正在运行,或者将在接下来的几个小时内运行。但是,我不知道如何将 scheduleinterval 对象与我使用 get-date 或 (get-date).addhours(20) 创建的变量进行比较

我正在查看的 scheduleInterval 是

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;}

任何帮助深表感谢。

谢谢

4

2 回答 2

1

这是一种测试作业是否以该Get-Date值运行的方法。也许可以进行比较starttime/endtime properties[datetime]但我无法测试,我只是假设..

$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!"
    }
  }
}
于 2012-09-21T05:23:16.207 回答
0

我编写了以下代码将 Microsoft.Exchange.Common.ScheduleInterval 转换为日期时间对象数组。希望有人可以改进我的代码...

$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) )
}

谢谢

于 2012-09-21T09:30:30.367 回答