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.