I have a simple powershell script that runs fine when I execute it from the powershell editor, but yields entirely different results when I run it from Windows Task Scheduler.
Original code is below ... simply want to copy the latest file from the m: drive.
$OriginalDir = "M:" $BackupDir = "c:\downloads\db" $LatestFile = Get-ChildItem -path m: -Name -ErrorAction SilentlyContinue | Sort-Object LastWriteDate -descending | select -last 1 Write-OutPut $LatestFile write-output $LatestFile | add-content C:\Scripts\Log.txt #Copy-Item -path $OriginalDir\$LatestFile $BackupDir\$LatestFile
Testing against Contents in the "M" drive:
When run from the powershell editor, I get the latest file (20170720 (Thursday).bak). When I run from Windows task scheduler, I get 20170717 (Monday).bak. I'm running from the same account, and am at a loss as to what is going on.