我有一个简单的PS脚本,如果我通过powershell运行,它会给我输出,但是如果我尝试通过预定任务运行,那么我就不会得到输出。该脚本正在运行,正在生成一个csv文件和一封邮件,但其中没有输出。
使用Task Scheduler参数测试,例如:
程序/脚本:C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe
添加参数:c:\ Temp \ temp_script \ pass_last_set.ps1
$dateformat= Get-Date -format 'MM.dd.yyyy.HH.mm.ss' # modified this to reflect the exact time in 24 hour format
$users = ForEach ($user in $(Get-Content -path "C:\Temp\temp_script\users.txt")) {
$date = "02/15/2019 01:00:00pM"
Get-ADUser -identity $user -Property passwordlastset | where-object {$_.passwordlastset -gt $date}
} $users | Select-Object Samaccountname,PasswordLastSet | Sort-Object PasswordLastset -Descending | export-csv "C:\Temp\temp_script\passreset-$($dateformat).csv" -NoTypeInformation -Append
$filename="C:\Temp\temp_script\passreset-$($dateformat).csv"
$body = (get-content $filename) -join '<BR>'
[string]$Htmlbody = $body
Send-MailMessage -To "abc@yahoo.com" -From "xyz@yahoo.com" -Subject "users - Report" -SmtpServer "xyz" -Attachments $filename -bodyashtml $Htmlbody"
Write-Host "Mail sent successfully"
我希望通过Windows Task Scheduler获得相同的输出。