Powershell Script in Task Scheduler Takes infinitely long time to run.


  • Hello, 
    I have created a task sequence which runs a powershell script. The powershell script is as follows:

    $pgList = Get-ProtectionGroup -DPMServerName 
    if ($pgList -ne $null) 
    [xml]$Doc = New-Object System.Xml.XmlDocument  
    $root = $doc.CreateNode("element","prtg",$null)
    foreach ($pg in $pgList) 
          $dsList = Get-DPMDatasource -ProtectionGroup $pg 
            foreach ($ds in $dsList) 
            $currentLastrecoveryTime =$ds.LatestRecoveryPointTime
            $ServerInfo=$ds.Name+" "+$ds.ProductionServerName
            $c = $doc.CreateNode("element","result",$null)
             $e = $doc.CreateElement("Channel")
             $e.InnerText = $ServerInfo
             $Val = $doc.CreateElement("Value")
             $Val.InnerText = $currentLastrecoveryTime
        } # end foreach $pg
    } # end If $pglist
    Invoke-Command –ComputerName –ScriptBlock $sb
    Copy-Item -path '\\\C$\custom.xml' -destination '\\\C$\DPMXMLFile' ## Move the files to the destination folder

    This script is on yyyy server and the task sequence is created on that server to run this script every one hour. It takes forever to run the script. Not sure what is wrong here. Can Any one help? Attached is the image of the XML file of the task sequence I created.

    Thank You.

    Monday, June 04, 2018 3:53 PM