Powershell Script in Task Sequence Takes infinitely long time to run

时间:2018-06-04 16:41:36

标签: powershell scheduled-tasks powershell-v3.0 dpm

I have created the task sequence for the powershell script. It should run after an hour and seems like task never ends. When I manually run the script, it finishes within 2 minutes. Below is my powershell script:

$sb={
    $pgList = Get-ProtectionGroup -DPMServerName xxx 
    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
             $c.AppendChild($e)
             $Val = $doc.CreateElement("Value")
             $Val.InnerText = $currentLastrecoveryTime
             $c.AppendChild($Val)
             $root.AppendChild($c)
            }
            $doc.AppendChild($root)
            $doc.save("C:\custom.xml")
        } }
    Invoke-Command –ComputerName dpm.grasslands.ab.ca –ScriptBlock $sb
    Copy-Item -path '\\xxx\C$\custom.xml' -destination '\\yyy\C$\DPMXMLFile' 

Attached is the XML file for task sequence. TaskSequenceXML Can anyone help please? Thank you.

0 个答案:

没有答案