locked
PowerShell - Task scheduler RRS feed

  • Question

  • Hi,

    I'm able to run the below powershell script manually and get the desired output, but when I schedule it through Task scheduler - I'm not getting any error but the file size is zero kb. 

    I have used powershell path as program path, used -File <xyz.ps1 file path> as argument, am I missing something ?

    --------------------------------------------------------------

    $Date = (Get-Date).AddDays(-31)

    Get-WinEvent -ComputerName xyz1.example.com -FilterHashtable @{logname='Microsoft-Windows-TerminalServices-Gateway/Operational';StartTime = $Date; ID = 300 } | Select-Object -Property TimeCreated, Id, ProviderName, Message |export-csv c:\logs\xyz1csv

    • Moved by Bill_Stewart Wednesday, May 30, 2018 7:28 PM Abandoned
    Monday, March 26, 2018 3:45 AM

All replies

  • Folder permissions? 

    Unfortunately this is not a task manager forum.  As you noted,  the script works.  You need to troubleshoot your task definition and permissions.


    \_(ツ)_/

    Monday, March 26, 2018 4:16 AM
  • Hi,

    I'm able to run the below powershell script manually and get the desired output, but when I schedule it through Task scheduler - I'm not getting any error but the file size is zero kb. 

    I have used powershell.exe path as program path, used -File <xyz.ps1 file path> as argument, am I missing something ?

    --------------------------------------------------------------

    $Date = (Get-Date).AddDays(-31)

    Get-WinEvent -ComputerName xyz1.example.com -FilterHashtable @{logname='Microsoft-Windows-TerminalServices-Gateway/Operational';StartTime = $Date; ID = 300 } | Select-Object -Property TimeCreated, Id, ProviderName, Message |export-csv c:\logs\xyz1csv

    • Merged by jrv Monday, March 26, 2018 11:38 AM DUPLICATE
    Monday, March 26, 2018 11:25 AM
  • You have already asked about this and you were told that it wasn't a scripting issue, have you followed the advice given?

    https://social.technet.microsoft.com/Forums/scriptcenter/en-US/23e9c423-1b88-4298-bf14-5019e96bc909/powershell-task-scheduler?forum=ITCG#23e9c423-1b88-4298-bf14-5019e96bc909


    Learn PowerShell                     Script Requests

    -Remember to mark the correct response as the answer-

    Monday, March 26, 2018 11:33 AM
  • You could use Start-Transcript within your PowerShell script to see what it does whilst running as a Scheduled Task.
    Monday, March 26, 2018 11:43 AM
  • Hi,

    Try to run the task with "run with highest privileges".

    Thanks,

    Kapil K

    Monday, March 26, 2018 11:51 AM
  • Thanks Kapil, tried "run with highest privileges" but no luck. However I have solved it. The solution was to save credentials as it is required for accessing any network resources. 

    http://technet.microsoft.com/en-us/library/cc722152.aspx

    • Edited by George K U Tuesday, April 3, 2018 1:26 AM
    Tuesday, April 3, 2018 1:22 AM