none
Task Scheduler task to run PS1 script to fetch data from outlook RRS feed

  • Question

  • Hello All,

    Need help/suggestions, Running below script on project server via task scheduler. Problem is, when running the task scheduler with service account - we are getting error (PFB) but if I run the script directly, it will work.  FYI: service account has admin privilege and logon as batch and service has the service account added.

    #######################################################

    Start-Transcript -Append -Path "F:\temp\Transcript0.txt"

    Echo "Starting Daily DW Reports Process"
    echo "Deleting files in c:\Reports\Rawfiles\"
    Echo "Starting the Daily Files Copy process"
    Remove-Item –path F:\Reports\Rawfiles\*.xlsx
    $Outlook = New-Object -ComObject Outlook.Application
    $Namespace = $Outlook.GetNameSpace("MAPI")
    echo $Namespace
    $fs=""
    Echo "Step 1 - Downloading attachments from Email"
    $fs = $Namespace.Folders.Item('svc.dwrptsE3@aexp.com').Folders.Item('dwreports')
    echo $fs
    $attachments=""
    Remove-Item F:\Reports\Rawfiles\*.*
    $saveFilePath = "F:\Reports\Rawfiles\"
    $filterdate= (Get-Date).AddDays(-1)
    foreach ($f in $fs.items)
    {
    if ($f.attachments.count -ge 1)

    {

            foreach ($attachment in $f.attachments)
    {


            if($attachment.FileName.Contains("DW") -and $f.ReceivedTime -gt $filterdate )
    {


            echo $f.ReceivedTime
            $filename = $attachment.filename
            $attachments=$attachments+$Filename
    $attachment.saveasfile((join-path $savefilepath $filename))
            }
            }
    }
    }
    echo " Starting  Python Program"
    python F:\PSScripts\KBfilesModify.py

    #######################################################

    Friday, November 1, 2019 1:08 PM