ZTree.com  | ZEN  | About...  

 Index   Back

[OT] Batch file sorting help   [OT]

By: Paul Laufer       
Date: Mar 21,2024 at 17:28
In Response to: [OT] Batch file sorting help (Ben Kent)

Thanks Ben, that was very helpful. I ended up using the call to powershell from the batch file, only needing to tweak it because the date format had two spaces between date and time.

Here's the whole thing if anyone wants it. I have not done any error checking for things like if an OST file doesn't exist since they will always exist on these machines, and it's strictly for my own use, and a few other very techie people.

Use case? Yeah it's strange, but we have 100 or more PC's that are in the odd position of having oftentimes >150 DIFFERENT USERS login during the course of a year or so. And each of those users then has two years worth of Outlook email data downloaded. So occasionally we need to clear a bunch of users off of the machine. This is something to help me decide who to kill. :)

@echo off
::OutlookOSTSizeCheck-v1.0.bat

::Purpose ---------------------------------------------------------
:: Returns a list of all *.OST files under the C:\Users\ directory.
:: OST files are the main database used by MS Outlook to store emails locally.
:: This is useful to find out usernames that are using up disk space but who have not logged in for a long time.

::ChangeLog -------------------------------------------------------
:: v1.0 - 03/15/2024 - Initial Release.

::Check to see if we're running as ADMIN (Not the only way... one of MANY potential ways)
IF EXIST %SYSTEMROOT%\SYSTEM32\WDI\LOGFILES GOTO ADMIN_YES
GOTO ADMIN_NO

::We're running as ADMIN so lets proceed.
:ADMIN_YES

Echo Working....

::Send the info to a TEMP file, overwriting any prior files we've created.
DIR /S /TW /4 /Q /OD C:\USERS\*.OST >%TEMP%\LookingForOST-1.TMP

::Strip away all lines other than those with .OST and send to a new file (so that when PowerShell runs next it only sees lines with properly formatted dates).
findstr /i ".ost" %TEMP%\LookingForOST-1.TMP > %TEMP%\LookingForOST-2.TMP

::Now use PowerShell to sort the data by date.
type %TEMP%\LookingForOST-2.TMP | powershell -c "$input | Sort-Object { [datetime]::ParseExact($_.substring(0, 20), 'MM/dd/yyyy hh:mm tt', $null)} " > %TEMP%\LookingForOST-3.TMP

::Make sure the screen is clear, and begin presentation to the user.
cls
Echo.
Echo Here is a list of OST files (Outlook data) in the C:\Users\ branch, sorted by last written date.
Echo.
Echo This is a reasonable indicator of when the user last launched MS Outlook
Echo and how much local disk space they are using for email storage.
Echo.
Echo If the hard drive is full, and you MUST clear up space, this may be useful information.
Echo.
Echo -------------------------------------------------------------------------------------

::Now find and show the users any lines from that temp file with ".ost" in the PathName.
type %TEMP%\LookingForOST-3.TMP
Echo -------------------------------------------------------------------------------------
Echo.
pause
GOTO END

::We're not running as ADMIN. Warn the user and exit.
:ADMIN_NO
CLS
echo OutlookOSTSizeCheck-v1.0.bat
Echo.
ECHO This batch file MUST be run as Administrator to work.
Echo.
Echo Aborting!
echo.
pause

:END
exit

880 views      
 

Messages in this Thread

 
96,640 Postings in 12,231 Threads, 350 registered users, 68 users online (0 registered, 68 guests)
Index | Admin contact |   Forum Time: Apr 12, 2024 - 3:43 pm UTC  |  Hits:62,818,977  (14,508 Today )
RSS Feed