Log file not being generated while running a script via Windows Task Scheduler

淺唱寂寞╮ 提交于 2019-12-10 11:17:54

问题


Log file not being generated while running a PowerShell script via Windows Task Scheduler.

Code as below:

function check-cert
{
  $cmd = "Certutil -crl"
  Invoke-Expression $cmd
  if($LASTEXITCODE -eq '0')
  {
    Write-Output $LASTEXITCODE
  }
  else
  {
    $output = $LASTEXITCODE 
    $date   = (Get-Date).ToString()
    $result = $date + " " + $output
    $result | Out-File "C:\users\admin\Documents\Powershell\crllog.txt" -Append
    Write-Host "crl failed to publish" 
  }
}

check-cert

Could you please help me in getting the log file while running the script via Task Scheduler?

When I run the PowerShell script using the PowerShell editor, the output file gets generated. But when scheduled via Windows Task Scheduler it doesn't.

来源:https://stackoverflow.com/questions/38042645/log-file-not-being-generated-while-running-a-script-via-windows-task-scheduler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!