• I looked at the "Output File Cleanup" Job in Ola Hallengrens script and rewrote it in powershell.

    Turning this:

    cmd /q /c "For /F "tokens=1 delims=" %v In ('ForFiles /P "$(ESCAPE_SQUOTE(SQLLOGDIR))" /m *_*_*_*.txt /d -30 2^>^&1') do if EXIST "$(ESCAPE_SQUOTE(SQLLOGDIR))"\%v echo del "$(ESCAPE_SQUOTE(SQLLOGDIR))"\%v& del "$(ESCAPE_SQUOTE(SQLLOGDIR))"\%v"

    Into this:

    powershell.exe -command & {get-childitem -path "$(ESCAPE_SQUOTE(SQLLOGDIR))" -filter *_*_*_*.txt | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-30)} | remove-item -verbose}

    It should handle UNC paths and i think it is a little bit easier on the eye. Cmd is probably faster to execute and it will probably work the same pretty much anywhere, the powershell snippet above has not been tested in production so be aware of that. I just did it for the sake of learning and i did it on SQL Server 2014 SP1 Enterprise. But if anyone else finds it useful, nobody is happier than me. 🙂