Scan PST file sizes on network

Most of the businesses I manage use Outlook (not exchange) for email.  I am starting to see PST files get way too large and Archiving either not working, or getting too large as well, requiring a manual archiving of the archive.

I would like a have a script or batch that can scan the computers on the network and report back the filesize of the PST files so I can keep an eye on them.  I could provide a list of the computer names if the script could loop through the list and check each profile location and the default Outlook location for each PST file and echo to a text document the computer name, profile name and pst filename with the file size.
murrycAsked:
Who is Participating?
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
I'm so fed up with this strange handling, really. Let's run a batch file from the location you store the log file to:

Triggering code:
@echo off
psexec @computers.txt -u YourDomain\YourUser -p YourPwd -d -n 5 -w "C:\Documents and Settings" cmd /q /c \\tyr-pdc\system\pst-sizes.cmd

Open in new window


pst-sizes.cmd:
@echo off
for /F "delims=" %%F in ('dir /s/b/a:-d *.pst') do echo %computername% * %%~fF * %%~zF >> %~dp0\pst-sizes.log

Open in new window

0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
That's much more complicated then you might think. The PST location is bound to user profiles. User profiles are only accessible (easily) if they are loaded - in use, that is.

Most admins will use a script running on each PC when logging in (or out). That is much easier. Is that an option?
0
 
Hari1612Commented:
I am not sure of your rights on the network computer. But you can use a simple dos based batch file and make it run on all computers on startup.

pstlist.bat
========

d:
dir /s *.pst ->d:\pstlistc.txt
c:
dir /s *.pst -?d:\pstlistd.txt

Then write a code to map a public folder and copy this file to the public folder with some ref as per computer name.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
That's too simplistic, has some flaws and some typos.
What if there is an E: drive?
Doing a complete scan of all drives is oversized for this purpose, a more direct approach should be taken.
How would you execute the batch remotely?

As I said - there is much more behind it.
0
 
murrycAuthor Commented:
I see your points.  We do know that the profiles are static no matter the current login, meaning that a loop scan of the 'documents and settings' folder will uncover the profiles on the remote computer.  We might could then loop back through the profiles scanning the \Local Settings\Application Data\Microsoft\Outlook location for the pst files.

Sound doable?
0
 
murrycAuthor Commented:
All of these are XP machines and the script would be running from a domain admin computer.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
My way to do that would be to create a scheduled task on each XP machine. But we can still trigger it remotely, if you like, but I recommend to use a free 3rd-party tool: psexec from www.sysinternals.com, which is now owned by Microsoft.

@echo off
psexec @computers.txt -d -e -n 5 -w "C:\Documents and Settings\" cmd /c @for %F in ('dir /s/b/a:-d *.pst) do @echo %computername% * %~fF * %~zF >> \\server\share\pst-sizes.log

Open in new window

That will spawn a process on each machine (taken from computers.txt), logging the sizes of all PST files on a centrally stored file. psexec detachs (-d) from the remote process, so while it is running can proceed with the next PC. Each PC needs to be available within 5 seconds (-n 5), else it is skipped.
0
 
murrycAuthor Commented:
I love psexec!  Thanks for the command.

When I execute it, I get the following...

D:\PST>pst
The following usage of the path operator in batch-parameter
substitution is invalid: %~fF * %~zF >> pst-sizes.log

For valid formats type CALL /? or FOR /?
The syntax of the command is incorrect.
D:\PST>psexec @computers.txt -d -e -n 5 -w "C:\Documents and Settings\" cmd /c @
for -d *.pst) do @echo ETRG-USER20 * echo %computername% * %~fF * %~zF >> pst-si
zes.log
D:\PST>
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Sorry, obviously I pasted the wrong commandline ...
psexec @computers.txt -d -n 5 -w "C:\Documents and Settings" cmd /c @for /F "delims=" %F in ('dir /s/b/a:-d *.pst') do @echo ^%computername^% * %~fF * %~zF ^>^> \\server\share\pst-sizes.log

Open in new window

This one is tested against XP machines (though triggered from Vista, but that shouldn't make any difference). Remember to change \\server\share to the correct location the log file should reside on.
0
 
murrycAuthor Commented:
Maybe there is a difference with running on Vista.  I am running it from  XP and here is the error...

D:\PST>pst.bat
The following usage of the path operator in batch-parameter
substitution is invalid: %~fF * %~zF ^>^> \\tyr-pdc\system\pst-sizes.log

For valid formats type CALL /? or FOR /?
pst.bat was unexpected at this time.

D:\PST>psexec @computers.txt -d -n 5 -w "C:\Documents and Settings" cmd /c @for
/F "delims=" -d *.pst') do @echo ^ * pst') do @echo ^%computername^% * %~fF * %~
zF ^>^> \\tyr-pdc\system\pst-sizes.log
D:\PST>
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
The above line was intended to be used in cmd.exe directly, not in a batch file. If called from batch, the line needs some modifications:
@echo off
psexec @computers.txt -d -n 5 -w "C:\Documents and Settings" cmd /q /c for /F "delims=" %%F in ('dir /s/b/a:-d *.pst') do echo ^%%computername^%% * %%~fF * %%~zF ^>^> \\tyr-pdc\system\pst-sizes.log

Open in new window


0
 
murrycAuthor Commented:
Is there any error checking we can add to this?  I am able to execute via the batch and psexec shows it is started on the remote machine, but the logfile (which is accessible from the remote computer) is never created or updated (when I have created it manually).

Here is the batch...

PsExec v1.72 - Execute processes remotely
Copyright (C) 2001-2006 Mark Russinovich
Sysinternals - www.sysinternals.com

\\tyr-mgmt03:

cmd started on tyr-mgmt03 with process ID 3852.
Press any key to continue . . .
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
For debugging, use this command as part of the batch - it will stay attached to the cmd.exe, only output to screen (no file), and we will see if there is an issue with the command itself that way:
psexec @computers.txt  -n 5 -w "C:\Documents and Settings" cmd /c for /F "delims=" %%F in ('dir /s/b/a:-d *.pst') do echo ^%%computername^%% * %%~fF * %%~zF

Open in new window

0
 
murrycAuthor Commented:

D:\PST>psexec @computers.txt  -n 5 -w "C:\Documents and Settings" cmd /c for /F
"delims=" %F in ('dir /s/b/a:-d *.pst') do echo %computername% * %~fF * %~zF

PsExec v1.72 - Execute processes remotely
Copyright (C) 2001-2006 Mark Russinovich
Sysinternals - www.sysinternals.com

\\tyr-mgmt03:

delims was unexpected at this time.
cmd exited on tyr-mgmt03 with error code 1.

D:\PST>pause
Press any key to continue . . .
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
What the heck is going on there? Please try
psexec @computers.txt  -n 5 -w "C:\Documents and Settings" cmd /c echo for /F "delims=" %%F in ('dir /s/b/a:-d *.pst') do echo ^%%computername^%% * %%~fF * %%~zF

Open in new window

0
 
murrycAuthor Commented:
Getting closer.  I am running this from a domain server that has admin rights to all of the workstations, so I am not sure what the access denied is related to.

Z:\PST>psexec @computers.txt  -n 5 -w "C:\Documents and Settings" cmd /c echo fo
r /F "delims=" %F in ('dir /s/b/a:-d *.pst') do echo %computername% * %~fF * %~z
F >> \\tyr-pdc\system\pst-sizes.log

PsExec v1.72 - Execute processes remotely
Copyright (C) 2001-2006 Mark Russinovich
Sysinternals - www.sysinternals.com

\\etrg-user10:

Access is denied.
cmd exited on etrg-user10 with error code 1.

Z:\PST>pause
Press any key to continue . . .
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
It is important that you do not append the >> part, as shown in my last post. The creation attempt of that log file might be the issue.
0
 
murrycAuthor Commented:
Gotcha...

Where will the results of the scan be recorded?  Here is the result within the log file.  It exits with a 0, which is normally good.


Z:\PST>psexec @computers.txt  -n 5 -w "C:\Documents and Settings" cmd /c echo fo
r /F "delims=" %F in ('dir /s/b/a:-d *.pst') do echo %computername% * %~fF * %~z
F

PsExec v1.72 - Execute processes remotely
Copyright (C) 2001-2006 Mark Russinovich
Sysinternals - www.sysinternals.com

\\etrg-user1:

for /F delims= %F in ('dir /s/b/a:-d *.pst') do echo ETRG-USER1 * %~fF * %~zF
cmd exited on etrg-user1 with error code 0.

Z:\PST>pause
Press any key to continue . . .
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Ok, that shows us the command would be executed correctly. Now the only issue is indeed the log file. The last step didn't write one, and succeeded. The step before that wanted to write into the log file, and got Access Denied. Either the user issueing psexec does not have privs to write to \\tyr-pdc\system\pst-sizes.log, or it is an "impersonating issue" (I have heard rumors about that).
Please try:
psexec \\etrg-user1 -n 5 -w "C:\Documents and Settings" cmd /c copy nul \\tyr-pdc\system\pst-sizes.log

Open in new window

and
psexec \\etrg-user1 -u YourDomain\YourUser -P YourPwd -n 5 -w "C:\Documents and Settings" cmd /c copy nul \\tyr-pdc\system\pst-sizes.log

Open in new window

(of course you need to replace the Your... values).
0
 
murrycAuthor Commented:
The first one fails with access denied.  The second one succeeds, copies the file and exits with 0.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Interesting, so there is indeed a difference. That means you need to provide explicit credentials to allow for network access.
Back to the previous issue then. That debug output really helped - there are double quotes removed from the "delims=", and that is the issue. And it is different to my Vista machine. I reckon this line should work:
@echo off
psexec @computers.txt -u YourDomain\YourUser -p YourPwd -d -n 5 -w "C:\Documents and Settings" cmd /q /c for /F ^"delims=^" %%F in ('dir /s/b/a:-d *.pst') do echo ^%%computername^%% * %%~fF * %%~zF ^>^> \\tyr-pdc\system\pst-sizes.log

Open in new window

(inside a batch file).
0
 
murrycAuthor Commented:
Ok, we are really close here (I can feel it).

I can execute the command in a batch file and the result is below.  I can monitor the remote computer (ETRG-USER56) and see the psexec show up in the processes for a split second then dissappear.  The log file never records anything.

PsExec v1.72 - Execute processes remotely
Copyright (C) 2001-2006 Mark Russinovich
Sysinternals - www.sysinternals.com

\\etrg-user56:

cmd started on etrg-user56 with process ID 2124.
Press any key to continue . . .
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Sigh. For debugging, remove the -d from psexec (again), so we can see the complete output. I suppose there is an error message you cannot see with -d.
0
 
murrycAuthor Commented:
I so greatly appreciate your continued support!

After removing -d...


PsExec v1.72 - Execute processes remotely
Copyright (C) 2001-2006 Mark Russinovich
Sysinternals - www.sysinternals.com

\\etrg-user56:

delims was unexpected at this time.
cmd exited on etrg-user56 with error code 1.
Press any key to continue . . .
0
 
murrycAuthor Commented:
Are you wanting me to run these from the tyr-pdc server?  This is where the log gets written to.
0
 
murrycAuthor Commented:
I created pst-sizes.cmd and placed it at \\tyr-pdc\system\ and then edited the original batch file with your current 'triggering code' and launch it against etrg-user56.

I think it worked!  Here is the log file, with accurate HUGE PST files.

ETRG-USER56 * C:\Documents and Settings\hlobley\Local Settings\Application Data\Microsoft\Outlook\archive.pst * 2121024512
ETRG-USER56 * C:\Documents and Settings\hlobley\Local Settings\Application Data\Microsoft\Outlook\Outlook.pst * 18950931456
ETRG-USER56 * C:\Documents and Settings\hlobley\Local Settings\Application Data\Microsoft\Outlook\Outlook_old.pst * 19751388160
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Great! You now might tweak the delimiter (*), or want to remove "C:\Documents and Settings" (as we know that part already).
0
 
murrycAuthor Commented:
Amazing!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.