I have two simple one line "scripts". They check how old are certain files in a certain folders. One displays the output to the screen and the other writes the output to a text file on the desktop. Both ".ps1" script files are saved on the desktop. Running either ".ps1" files using "Run with PowerShell" gets results that are not correct. When running either ".ps1" files via PowerShell ISE the result is different (and correct).
The first script:
cd G:\moveh\back
Get-ChildItem -filter "*.rar" | Foreach-Object { if ( ((get-date).toshortdatestring() ) -gt ($_.lastwritetime.toshortdatestring() ) ) { "{0} {1}" -f $_.name,$_.lastwritetime.toshortdatestring()} }
cmd /c pause
The second script:
Get-ChildItem $allfolders | where {$_.Name -notlike "*closed"} | gci - Recurse -File -filter "Data.rar" | where {( ($_.lastwritetime.toshortdatestring()) -lt ((get-date).AddDays(-1).ToShortDateString() ) ) } | format-table -autosize -Property Directory, Name, LastWriteTime > C:\Users\itsupport\Desktop\Files_2b_updated_DB.txt
An example screenshot with the two different results for the first script:
Any ideas why there are different results?