SCOM Task fails with error code -2130771868

Peter Svensson 211 Reputation points
2021-02-04T07:39:21.613+00:00

I have a SCOM task running a powershell script that lists the largest folders on a disk.
Most of the time it runs great but sometimes I get an error:
The SCOM task failed with error code -2130771868
I believe this has to do with the Task time-outs.

I clocked it on a server having an issue.
Running the SCOM task it takes about 90 sec before I get the error.
Running the same script directly on the server takes about 200 sec and then a result is produced.

The timeout value for the task is set to 300 sec
<DeviceID>$Target/Property[Type="Windows!Microsoft.Windows.LogicalDevice"]/DeviceID$</DeviceID>
<TimeoutSeconds>300</TimeoutSeconds>

So somehow the task ignores the Timeoutvalue? Or something else is wrong.

Any ideas?

Operations Manager
Operations Manager
A family of System Center products that provide infrastructure monitoring, help ensure the predictable performance and availability of vital applications, and offer comprehensive monitoring for datacenters and cloud, both private and public.
1,507 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. CyrAz 5,181 Reputation points
    2021-02-04T08:15:44.107+00:00

    Could you show us the full code for the task? Powershell timeout could be shorter than task timeout, or anything else could be wrong...

    0 comments No comments

  2. Peter Svensson 211 Reputation points
    2021-02-04T09:25:04.46+00:00

    [64001-task.txt][1] [1]: /api/attachments/64001-task.txt?platform=QnA Couldn't paste the code, attached it instead

    0 comments No comments

  3. CyrAz 5,181 Reputation points
    2021-02-04T09:37:42.153+00:00

    At a first glance it looks fairly basic and properly done, but it doesn"t include te powershell script itself... could you post it as well?

    0 comments No comments

  4. Peter Svensson 211 Reputation points
    2021-02-04T11:19:47.643+00:00
    param(
       [string]$DeviceID
    )
    
    $DeviceID = $DeviceID +'\'
    $allFolders = Get-ChildItem -Literalpath $DeviceID -Directory -Force
    
    #Create array to store folder objects found with size info.
    [System.Collections.ArrayList]$folderList = @()
    
    #Go through each folder in the base path.
    ForEach ($folder in $allFolders) {
    
        #Clear out the variables used in the loop.
        $fullPath = $null        
        $folderObject = $null
        $folderSize = $null
        $folderSizeInMB = $null
        $folderSizeInGB = $null
        $folderBaseName = $null
    
        #Store the full path to the folder and its name in separate variables
        $fullPath = $folder.FullName
        $folderBaseName = $folder.BaseName
        $folderLastWrite = $folder.LastWriteTime  
    
    
        #Get timeago
        $timeago = ((Get-Date) - $folderLastWrite)
        $timeagomin = [math]::Round($timeago.Minutes)
    
        #Write-Verbose "Working with [$fullPath]..."            
    
        #Get folder info / sizes
        $folderSize = Get-Childitem -Path $fullPath -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue       
    
        #We use the string format operator here to show only 2 decimals, and do some PS Math.
        $folderSizeInMB = "{0:N0}" -f ($folderSize.Sum / 1MB)
        $folderSizeInGB = "{0:N2}" -f ($folderSize.Sum / 1GB)
    
        #Here we create a custom object that we'll add to the array
        $folderObject = [PSCustomObject]@{
    
            Path          = $fullPath
            #FolderName    = $folderBaseName
            'Size(Bytes)' = $folderSize.Sum
            #'Size(MB)'    = $folderSizeInMB
            'Size(GB)'    = $folderSizeInGB
            #LastwriteTime = $folderLastWrite
            TimeAgoMinutes  = $timeagomin
    
        }                        
    
        #Add the object to the array
        $folderList.Add($folderObject) | Out-Null
    
    }
    
    
    #Return the object array with the objects selected in the order specified.
    $folderList | sort-object 'Size(Bytes)' -Descending | select -First 20 | ConvertTo-Json
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.