Home General Discussion

Is there a way to set up a re-occuring SR?

Lesley_MunroLesley_Munro Customer IT Monkey ✭

I have been asked if we can setup a SR to be automatically created each Monday, to asisst an analyst with managing part of their role as our backup administrator.

Best Answer

Answers

  • Adam_DzyackyAdam_Dzyacky Product Owner Contributor Monkey ✭✭✭✭✭

    This sounds like a job for Orchestrator or SMA.

  • Lesley_MunroLesley_Munro Customer IT Monkey ✭

    sma?

  • Lesley_MunroLesley_Munro Customer IT Monkey ✭

    Perfect thank you!

  • Mikkel_MadsenMikkel_Madsen Customer Advanced IT Monkey ✭✭✭

    You can also accomplish this by using the task scheduler in windows.

    If you only have a few re-occuring requests and don’t have Orchestrator you can use windows task scheduler on the server to run a powershell code that creates the service request.

    This is just an example on one of our re-occuring Change Request but it is almost the same for Service Requests


    Import-Module Smlets
    
    
    $dkCulture = New-Object System.Globalization.CultureInfo("da-DK")
    $crTitle = "Udfasning af computere: " + [datetime]::now.ToString("MMMM",$dkCulture)
    $CrClass = Get-SCSMClass -name System.WorkItem.ChangeRequest$
    $Params = @{
    ID="CR{0}"
    Title=$crTitle
    ScheduledStartDate=[datetime]::utcnow
    ScheduledEndDate=[datetime]::utcnow.AddMonths(1).AddDays(7)
    }
     
    $o = New-SCSMObject -Class $CrClass -PropertyHashtable $Params -pass
     
    $title = $o.Id
    $changeRequest = Get-SCSMObjectProjection System.WorkItem.ChangeRequestProjection -filter "Id -eq '$title'"
     
    $template = get-scsmobjecttemplate Template.adac6669550d4693ae92350234e9bcfb
     
    $changeRequest.__base.ApplyTemplate($template)
    $changeRequest.__base.Commit()
    
    
    $Activities = Get-SCSMRelatedObject -SMObject $o -Depth Recursive | ?{$_.TypeName -like "System.WorkItem.Activity.*"}
    
    
    foreach ($Activity in $Activities)
    {
    $activityTitle = $Activity.Title
        #Write-Host "Activity Updated $($Activity.id) with Title $($Activity.Title)"
        $Activity | Set-SCSMObject -Property Title -Value "$crTitle - $activityTitle"
    
    
    
    
    
    
        switch ($activityTitle) {
        'Registrer enheder til udfasning' {
            $Activity | Set-SCSMObject -Property ScheduledStartDate -Value $([datetime]::utcnow)
            $Activity | Set-SCSMObject -Property ScheduledEndDate -Value $([datetime]::utcnow.AddMonths(1).AddDays(-1))
            Break
        }
        'Kontroller ark'{
            $Activity | Set-SCSMObject -Property ScheduledStartDate -Value $([datetime]::utcnow.AddMonths(1))
            $Activity | Set-SCSMObject -Property ScheduledEndDate -Value $([datetime]::utcnow.AddMonths(1).AddDays(7))
            break
        }
        'Slet computere i AD' {
            $Activity | Set-SCSMObject -Property ScheduledStartDate -Value $([datetime]::utcnow.AddMonths(1))
            $Activity | Set-SCSMObject -Property ScheduledEndDate -Value $([datetime]::utcnow.AddMonths(1).AddDays(7))
            break
        }
         }
    }
    
  • Adam_DzyackyAdam_Dzyacky Product Owner Contributor Monkey ✭✭✭✭✭
    edited February 2020

    @Mikkel_Madsen has the fastest to implement solution if the other components aren't currently deployed in your environment.

Sign In or Register to comment.