none
SCSM 2012 Workflow not running consistently

    Soru

  • I have the workflow which is triggered when  an incident is updated and changed from Status = Active or Status = Active/Pending to Status = Resolved. The workflow sets the ActualEndDate property to the current date/time. It seems to work once and it then stops working. I can see the workflow running and it does output the $objectID value but it seems like the module is not getting loaded when it doesn't work as the output doesn't show the module. Any ideas why the module would not be loaded? Should I load the module differently?

    Thanks, Ray

    Script Properties

    ObjectID = Activity=IM_Incident_SetActualEndDate, Path=SetActualEndDate_ObjectID

    Script Body

    param($ObjectID)

    CD 'C:\Program Files\Microsoft System Center 2012\Service Manager\Powershell'
    Import-Module .\System.Center.Service.Manager.psd1

    $Logfile = "C:\Temp\SCSM-SetActualEndDate-Incidents.txt"
    $a = (get-module|%{$_.name}) -join " "
    Add-Content -Path $Logfile "Modules1: $a"

    # Get the object to work on and record the current ActualEndDate
    $IncidentClass = Get-SCClass -Name System.workitem.incident

    $SCClassInstance = Get-SCClassInstance -Class $IncidentClass -Filter "Name -eq $ObjectID"
    $before = $SCClassInstance.ActualEndDate
    $SCClassInstance.ActualEndDate = [datetime]::now

    # Set the Actual End Date
    Update-SCClassInstance -Instance $SCClassInstance

    $SCClassInstance = Get-SCClassInstance -Class $IncidentClass -Filter "Name -eq $ObjectID"
    $after = $SCClassInstance.ActualEndDate

    Add-Content -Path $Logfile "Set the ActualEndDate for Incident: $ObjectID to: $after"

    Remove-Module System.Center.Service.Manager


    Ray

    12 Mart 2012 Pazartesi 14:26

Yanıtlar

Tüm Yanıtlar

  • You tried to load the module by the full path?

    import-module "C:\Program Files\Microsoft System Center\Service Manager 2012\Powershell\System.Center.Service.Manager.psd1"

    Also what happens if you run the script in a PowerShell with $ObjectID = "IR1234" at the beginning of the script? 


    Andreas Baumgarten | H&D International Group

    12 Mart 2012 Pazartesi 21:34
    Moderatör
  • Run this SQL Query against the ServiceManager database to see the complete error message:
    (Click the XML link in the query results to see the error)

    select 
    	job.TimeScheduled,
    	job.TimeStarted,
    	job.TimeFinished,
    	job.ErrorCode,
    	job.ErrorMessage,
    	convert(xml,job.Output),
    	job.Status,
    	Disp.DisplayName from JobStatusView  Job
    join DisplayStringView Disp
    on job.TaskId = disp.LTStringId
    where SubmittedBy = 'DOMAIN\WORKFLOW_ACCOUNT' and disp.LanguageCode = 'enu'
    order by TimeScheduled desc

    Regards
    //Anders

    Anders Asp | Lumagate | www.lumagate.com | Sweden | My blog: www.scsm.se

    14 Mart 2012 Çarşamba 08:44
    Moderatör
  • Thanks for the SQL query, that really helps when trying to figure out what’s wrong. This is the error I'm receiving.  The strange thing is that the workflow runs successfully one time and then starts getting errors… I tried running the script passing the incident number to it (IR1234) and it always runs without any issues. Also, it says the module is already loaded but I tried to output the module to the log file but the log doesn’t show it loaded.

    $a = (get-module|%{$_.name}) -join " "

    Add-Content -Path $Logfile "Modules1: $a"

     

    Errors

    Import-Module : The following error occurred while loading the extended type data file:  Microsoft.PowerShell, C:\Program Files\Microsoft System Center 2012\Service Manager\Powershell\Microsoft.EnterpriseManagement.Core.Cmdlets\Microsoft.EnterpriseManagement.Core.Cmdlets.Types.ps1xml : File skipped because it was already present from "Microsoft.PowerShell".

     

    Then I get the following error which is pointing to the module not being loaded...I would think this would work since the module is already loaded?

    The term 'Get-SCClass' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

     

    I also try to remove the module at the end of the script to cleanup and get an error…

     

    Remove-Module : No modules were removed. Verify that the specification of modules to remove is correct and those modules exist in the runspace.

     

     

    This is the modified script.

    Import-Module 'C:\Program Files\Microsoft System Center 2012\Service Manager\Powershell\System.Center.Service.Manager.psd1' -force

    $Logfile = "C:\Temp\SCSM-SetActualEndDate-Incidents.txt"

    $a = (get-module|%{$_.name}) -join " "

    Add-Content -Path $Logfile "Modules1: $a"

    # Get the object to work on and record the current ActualEndDate

    $IncidentClass = Get-SCClass -Name System.workitem.incident

    $SCClassInstance = Get-SCClassInstance -Class $IncidentClass -Filter "Name -eq $ObjectID"

    $before = $SCClassInstance.ActualEndDate

    $SCClassInstance.ActualEndDate = [datetime]::now

    # Set the Actual End Date

    Update-SCClassInstance -Instance $SCClassInstance

    $SCClassInstance = Get-SCClassInstance -Class $IncidentClass -Filter "Name -eq $ObjectID"

    $after = $SCClassInstance.ActualEndDate

    Add-Content -Path $Logfile "Set the ActualEndDate for Incident: $ObjectID to: $after"

    Remove-Module System.Center.Service.Manager

     

    Ray

    19 Mart 2012 Pazartesi 13:34
  • What is the start time, end time and output (can't remember the exact name of column) of the preceeding workflow?

    Regards
    //Anders


    Anders Asp | Lumagate | www.lumagate.com | Sweden | My blog: www.scsm.se

    19 Mart 2012 Pazartesi 13:41
    Moderatör
  • I'm not sure what your asking. I only have the single workflow firing against the incident when its closed.

    Ray


    Ray

    19 Mart 2012 Pazartesi 15:09
  • Import-Module : The following error occurred while loading the extended type data file:  Microsoft.PowerShell, C:\Program Files\Microsoft System Center 2012\Service Manager\Powershell\Microsoft.EnterpriseManagement.Core.Cmdlets\Microsoft.EnterpriseManagement.Core.Cmdlets.Types.ps1xml : File skipped because it was already present from "Microsoft.PowerShell".

    This is old-old problem existing from SCSM 2010. And if you face with that then there is no solution to resolve that but you can try some tips from this topic:

    http://social.technet.microsoft.com/Forums/en-US/administration/thread/4d7929d3-25c7-4687-a5f0-bab915435aa5


    http://www.scsmsolutions.com/ freemanru (at) gmail (dot) com

    19 Mart 2012 Pazartesi 16:02
    Moderatör
  • Yeah, but you wrote that it's working once before it starts to generate these kind of errors. How does that successful WF look when running the SQL query?

    Regards
    //Anders


    Anders Asp | Lumagate | www.lumagate.com | Sweden | My blog: www.scsm.se

    19 Mart 2012 Pazartesi 16:24
    Moderatör
  •  

    When it runs sucessfully this is the output from the SQL Query.

    <DataItem type="Microsoft.Windows.SerializedObjectData" time="2012-03-19T13:18:21.7547699Z" sourceHealthServiceId="7c156751-bb87-9973-1970-76b45c4b93cb">

      <SerializationSettings Type="OpsMgrSerialization" Depth="3" />

      <Description />

    </DataItem>


    Ray

    19 Mart 2012 Pazartesi 19:42
  • Also, If I restart the SCSM services and run the workflow again it runs like a champ!


    Ray

    19 Mart 2012 Pazartesi 19:59
  • Try this:

    http://blogs.technet.com/b/servicemanager/archive/2013/01/10/resolving-the-error-file-skipped-because-it-was-already-present-from-microsoft-powershell.aspx

    Please mark this as answer if it works for you.


    Travis Wright, Principal Program Manager, Microsoft

    10 Ocak 2013 Perşembe 22:23
    Sahip