Local PST Search

Discussion in 'Scripting' started by snorbens, Mar 17, 2010.

  1. snorbens

    snorbens Guest

    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
     
    snorbens, Mar 17, 2010
    #1
    1. Advertising

  2. snorbens

    snorbens Guest

    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
     
    snorbens, Mar 18, 2010
    #2
    1. Advertising

  3. hhh
    "snorbens" <> escribió en el mensaje de
    noticias news:...
    > 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
    >
     
    Nelson Rodriguez, Mar 19, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Byron Hinson

    Re: Search doesn't show PST files

    Byron Hinson, Dec 1, 2006, in forum: Windows Vista File Management
    Replies:
    0
    Views:
    382
    Byron Hinson
    Dec 1, 2006
  2. DGuess
    Replies:
    0
    Views:
    1,081
    DGuess
    Mar 8, 2007
  3. Spin
    Replies:
    0
    Views:
    642
  4. Replies:
    0
    Views:
    1,915
  5. rob
    Replies:
    2
    Views:
    207
Loading...

Share This Page