Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Local PST Search

Reply
Thread Tools Display Modes

Local PST Search

 
 
snorbens
Guest
Posts: n/a

 
      03-17-2010
Hi,

I have been asked to write a script to audit local drives of all
workstations for any PST files. I found a script, from another thread here a
few years back, which I have tried to modify to write found files to a text
document but I can't get it to write all files found to a text document.
It will write files found on the C:\ drive to the text document but there
are some on a second drive (D:\) but I get a script error stating "Permission
Denied". When I click on on the error box, it proceeds to write the text file
but only with what was found on the C:\ drive.

However, if I comment out all lines relating to creating & writing to the
TextFile, the Wscript.Echo will display PST files on the D:\ drive as well
as the C:\ drive.

My script is as follows:

Set objWSHShell = Wscript.CreateObject("Wscript.Shell")
strLogonServer = objWSHShell.ExpandEnvironmentStrings("%LOGONSERVER %")
Set objNet = CreateObject("Wscript.Network")
strComputer = objNet.ComputerName

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
strLogPath = strLogonServer & "\NETLOGON\Logs\PSTAudit" & "\" & strComputer
& ".txt"


Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(strLogPath) Then
Wscript.Quit
Else
Set dc = fso.Drives

For Each d in dc

if d.DriveType = 2 then 'fixed drives only

Set colFiles = objWMIService.ExecQuery("Select * from " & _
"CIM_DataFile where (Drive='" & d.DriveLetter & ":') " & _
"and (Extension = 'pst')")

If colFiles.Count = 0 Then
Wscript.Quit
End If

Set TextFile = fso.CreateTextFile(strLogPath)
For Each objFile in colFiles

'1KB = 1024 bytes
FileSizeKB = objFile.FileSize \ 1024
'1MB = 1024 * 1024 bytes (1KB * 1024)
FileSizeMB = objFile.FileSize \ 1024 \ 1024
'1GB = 1024 * 1024 * 1024 bytes (1MB * 1024)
FileSizeGB = objFile.FileSize \ 1024 \ 1024 \ 1024
If FileSizeGB >= 1 Then
Wscript.Echo objFile.Name & " " & FileSizeGB & " GBytes"
TextFile.Write(objFile.Drive & objFile.Path & objFile.Name & "." &
objFile.Extension & ",")
TextFile.Write(FileSizeGB & " GB" & vbCrLf)
ElseIf FileSizeMB >= 1 Then
Wscript.Echo objFile.Name & " " & FileSizeMB & " MBytes"
TextFile.Write(objFile.Drive & objFile.Path & objFile.Name & "." &
objFile.Extension & ",")
TextFile.Write(FileSizeMB & " MB" & vbCrLf)
ElseIf FileSizeKB >= 1 Then
Wscript.Echo objFile.Name & " " & FileSizeKB & " KBytes"
TextFile.Write(objFile.Drive & objFile.Path & objFile.FileName & "."
& objFile.Extension & ",")
TextFile.Write(FileSizeKB & " KB" & vbCrLf)
Else
Wscript.Echo objFile.Name & " " & objFile.FileSize & " Bytes"
TextFile.Write(objFile.Drive & objFile.Path & objFile.FileName & "."
& objFile.Extension & ",")
TextFile.Write(objFile.FileSize & " Bytes" & vbCrLf)
End If
Next

end if

Next
objTextFile.Close
End If

I have checked security permissions on the drive and I have full control
over it besides wscript.echo does display contents of all drives so I don't
believe it is a permissions issue on the drive itself.

Can someone help me where I am going wrong? I'm sure it is something simple
I am overlooking.

Many Thanks

 
Reply With Quote
 
 
 
 
snorbens
Guest
Posts: n/a

 
      03-18-2010

It's OK, I found where I was going wrong.

The line to create the text file was in the wrong place. They should be just
before the this line:

For Each d in dc
 
Reply With Quote
 
 
 
 
Nelson Rodriguez
Guest
Posts: n/a

 
      03-19-2010
hhh
"snorbens" <> escribió en el mensaje de
noticias news:9320F039-0643-4A53-B20B-...
> Hi,
>
> I have been asked to write a script to audit local drives of all
> workstations for any PST files. I found a script, from another thread here
> a
> few years back, which I have tried to modify to write found files to a
> text
> document but I can't get it to write all files found to a text document.
> It will write files found on the C:\ drive to the text document but there
> are some on a second drive (D:\) but I get a script error stating
> "Permission
> Denied". When I click on on the error box, it proceeds to write the text
> file
> but only with what was found on the C:\ drive.
>
> However, if I comment out all lines relating to creating & writing to the
> TextFile, the Wscript.Echo will display PST files on the D:\ drive as
> well
> as the C:\ drive.
>
> My script is as follows:
>
> Set objWSHShell = Wscript.CreateObject("Wscript.Shell")
> strLogonServer = objWSHShell.ExpandEnvironmentStrings("%LOGONSERVER %")
> Set objNet = CreateObject("Wscript.Network")
> strComputer = objNet.ComputerName
>
> Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
> strLogPath = strLogonServer & "\NETLOGON\Logs\PSTAudit" & "\" &
> strComputer
> & ".txt"
>
>
> Set fso = CreateObject("Scripting.FileSystemObject")
> If fso.FileExists(strLogPath) Then
> Wscript.Quit
> Else
> Set dc = fso.Drives
>
> For Each d in dc
>
> if d.DriveType = 2 then 'fixed drives only
>
> Set colFiles = objWMIService.ExecQuery("Select * from " & _
> "CIM_DataFile where (Drive='" & d.DriveLetter & ":') " & _
> "and (Extension = 'pst')")
>
> If colFiles.Count = 0 Then
> Wscript.Quit
> End If
>
> Set TextFile = fso.CreateTextFile(strLogPath)
> For Each objFile in colFiles
>
> '1KB = 1024 bytes
> FileSizeKB = objFile.FileSize \ 1024
> '1MB = 1024 * 1024 bytes (1KB * 1024)
> FileSizeMB = objFile.FileSize \ 1024 \ 1024
> '1GB = 1024 * 1024 * 1024 bytes (1MB * 1024)
> FileSizeGB = objFile.FileSize \ 1024 \ 1024 \ 1024
> If FileSizeGB >= 1 Then
> Wscript.Echo objFile.Name & " " & FileSizeGB & " GBytes"
> TextFile.Write(objFile.Drive & objFile.Path & objFile.Name & "." &
> objFile.Extension & ",")
> TextFile.Write(FileSizeGB & " GB" & vbCrLf)
> ElseIf FileSizeMB >= 1 Then
> Wscript.Echo objFile.Name & " " & FileSizeMB & " MBytes"
> TextFile.Write(objFile.Drive & objFile.Path & objFile.Name & "." &
> objFile.Extension & ",")
> TextFile.Write(FileSizeMB & " MB" & vbCrLf)
> ElseIf FileSizeKB >= 1 Then
> Wscript.Echo objFile.Name & " " & FileSizeKB & " KBytes"
> TextFile.Write(objFile.Drive & objFile.Path & objFile.FileName & "."
> & objFile.Extension & ",")
> TextFile.Write(FileSizeKB & " KB" & vbCrLf)
> Else
> Wscript.Echo objFile.Name & " " & objFile.FileSize & " Bytes"
> TextFile.Write(objFile.Drive & objFile.Path & objFile.FileName & "."
> & objFile.Extension & ",")
> TextFile.Write(objFile.FileSize & " Bytes" & vbCrLf)
> End If
> Next
>
> end if
>
> Next
> objTextFile.Close
> End If
>
> I have checked security permissions on the drive and I have full control
> over it besides wscript.echo does display contents of all drives so I
> don't
> believe it is a permissions issue on the drive itself.
>
> Can someone help me where I am going wrong? I'm sure it is something
> simple
> I am overlooking.
>
> Many Thanks
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to sync a PocketPC with a .pst file other than outlook.pst? rob ActiveSync 2 03-27-2007 06:25 AM
Re: Seo , Search Engine Optimizer , Seo Search engine Optimization , search engine optimization services, SEO Consulting DGuess Windows Vista Mail 0 03-08-2007 06:59 AM
RE: Search doesn't show PST files Darrell Gorter[MSFT] Windows Vista File Management 0 11-30-2006 07:21 PM
re: domain.local, _msdcs.domain.local and the delegation for _msdcs.domain.local under domain.local rick.kingslan@microsoft.com DNS Server 0 10-26-2005 04:29 AM
domain.local, _msdcs.domain.local and the delegation for _msdcs.domain.local under domain.local Spin DNS Server 0 10-25-2005 11:46 PM