locked
Notification after 3 business days of inactivity RRS feed

  • Question

  • I have a subscription in place like:

    Notify periodically
    
    If Active
    
    And If Last modified is less than or equal to <relative> [now-3d]

    So it notifies upon any active incident that has not been touched in 3 days.  It works but I dont know how to make it only recognize business days.  If i could take advantage of the SLA calendar I have in place so that it would only use business hours that would be great.

    Any ideas? 


    - Get on the floor, do that dinosaur

    Monday, July 15, 2013 6:58 PM

Answers

  • I could not get the $BusinessDays concept to work, but played with it and got this to work

    $targetDays = 3;

    $today = [System.DateTime]::Now.Date

    $currentDay = $today.DayOfWeek 

    if($currentDay -eq [System.DayOfWeek]::Monday `
    -or $currentDay -eq [System.DayOfWeek]::Tuesday `
    -or $currentDay -eq [System.DayOfWeek]::Wednesday)
    {
    $targetDays = $targetDays + 2
    }
    if($currentDay -eq [System.DayOfWeek]::Sunday)
    {
    $targetDays = $targetDays + 1
    }

    $targetTimeSpan = [System.TimeSpan]::FromDays($targetDays)

    $targetDate = $today.Subtract($targetTimeSpan)

    $incident = Get-SCSMIncident -Status active |?{$_.LastModified -lt $targetDate}
    $incident

    Gary Davidson  |  gary.davidson@cireson.com  |  Boca Raton, FL

    Check out our System Center App Store: www.cireson.com/app-store



    • Edited by Gary L Davidson Saturday, July 20, 2013 10:34 PM correct typo
    • Marked as answer by Pete Barbuto Monday, July 22, 2013 12:33 PM
    Saturday, July 20, 2013 10:33 PM

All replies

  • 

    Below is my script so far.  I need help with the Get-SCSMEnumeration declaring multiples.  If I run  Get-SCSMEnumeration Calendar.DayOfWeek.Tuesday I’ll get what I want, its adding all the days that doesn’t work.  In addition, in the last section where $BusinessDays is more like pseudo-code at this point.  How do I format that?

    #Declare business days
    $Monday = Get-SCSMEnumeration Calendar.DayOfWeek.Monday
    $Tuesday = Get-SCSMEnumeration Calendar.DayOfWeek.Tuesday
    $Wednesday = Get-SCSMEnumeration Calendar.DayOfWeek.Wednesday
    $Thursday = Get-SCSMEnumeration Calendar.DayOfWeek.Thursday
    $Friday = Get-SCSMEnumeration Calendar.DayOfWeek.Friday
    #Define business days only
    
    $BusinessDays = @(Get-SCSMEnumeration | ?{($_.Displayname -eq $Monday -AND $_.Displayname -eq $Tuesday -AND $_.Displayname -eq $Wednesday -AND $_.Displayname -eq $Thursday -AND $_.Displayname -eq $Friday)})
    
    #Get all active incidents that have not been modified in past 3 business days
    $LastModifiedBreached = New-Object Timespan 3,0,0,0,0 | where $BusinessDays
    $incident = Get-SCSMIncident -Status active |?{$_.LastModified -lt (Get-Date).Subtract($LastModifiedBreached)}
    $incident



    - Get on the floor, do that dinosaur

    Wednesday, July 17, 2013 6:18 PM
  • I could not get the $BusinessDays concept to work, but played with it and got this to work

    $targetDays = 3;

    $today = [System.DateTime]::Now.Date

    $currentDay = $today.DayOfWeek 

    if($currentDay -eq [System.DayOfWeek]::Monday `
    -or $currentDay -eq [System.DayOfWeek]::Tuesday `
    -or $currentDay -eq [System.DayOfWeek]::Wednesday)
    {
    $targetDays = $targetDays + 2
    }
    if($currentDay -eq [System.DayOfWeek]::Sunday)
    {
    $targetDays = $targetDays + 1
    }

    $targetTimeSpan = [System.TimeSpan]::FromDays($targetDays)

    $targetDate = $today.Subtract($targetTimeSpan)

    $incident = Get-SCSMIncident -Status active |?{$_.LastModified -lt $targetDate}
    $incident

    Gary Davidson  |  gary.davidson@cireson.com  |  Boca Raton, FL

    Check out our System Center App Store: www.cireson.com/app-store



    • Edited by Gary L Davidson Saturday, July 20, 2013 10:34 PM correct typo
    • Marked as answer by Pete Barbuto Monday, July 22, 2013 12:33 PM
    Saturday, July 20, 2013 10:33 PM
  • Gary, that works great.  Thank you!

    - Get on the floor, do that dinosaur

    Monday, July 22, 2013 12:33 PM