powershell & BAT RRS feed

  • General discussion

  • I'm running a BAT script and inside that I'm running this: powershell.exe "&{exit (Get-date).AddDays(-1).ToString('MMddyy')}"

    I want to find yesterdays date.

    When I run the BAT script on my desktop and echo %ERRORLEVEL% after that line, it works fine and returns 111517 but when I run it in a different environment, it comes back with a number that doesn't resemble a date at all:   45881

    Has anyone seen this behavior and if so, did you find a solution to the problem?

    • Changed type Bill_Stewart Thursday, January 25, 2018 10:29 PM
    • Moved by Bill_Stewart Thursday, January 25, 2018 10:29 PM User should not be doing this
    Thursday, November 16, 2017 4:00 PM

All replies

  • Don't run powershell from a batch file. Use a PowerShell script and you get the benefit of real DateTime objects.

    -- Bill Stewart [Bill_Stewart]

    Thursday, November 16, 2017 4:21 PM