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

    Frage

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

    $sb={
    $pgList = Get-ProtectionGroup -DPMServerName dpm.grasslands.ab.ca 
    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")
        } # end foreach $pg
            
    } # end If $pglist
    }
    Invoke-Command –ComputerName dpm.grasslands.ab.ca –ScriptBlock $sb
    Copy-Item -path '\\dpm.grasslands.ab.ca\C$\custom.xml' -destination '\\prtg.grasslands.ab.ca\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.

    Montag, 4. Juni 2018 15:53