Home All Groups Group Topic Archive Search About


Author
21 Nov 2007 2:02 PM
LMac
Hi

I need to output a list of pst files from a server into a text file.  I have
found this script which will show on screen the files but unable to find out
how to export the list to a txt file.  Can this be done?

Thanks

----------------------------------------------------
Option Explicit

Dim fso, objF, d, dc
Dim objWMIService, colFiles, objFile
Dim FileSizeKB, FileSizeMB, FileSizeGB

Set objWMIService = _
GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

Set fso = CreateObject("Scripting.FileSystemObject")

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')")
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"
ElseIf FileSizeMB >= 1 Then
Wscript.Echo objFile.Name & " " & FileSizeMB & " MBytes"
ElseIf FileSizeKB >= 1 Then
Wscript.Echo objFile.Name & " " & FileSizeKB & " KBytes"
Else
Wscript.Echo objFile.Name & " " & objFile.FileSize & " Bytes"
End If

Next

end if

Next

Author
21 Nov 2007 2:46 PM
Richard Mueller [MVP]
Run the script at a command prompt with the cscript host and redirect the
output to a text file. For example if the script is called FindPst.vbs:

cscript //nologo FindPst.vbs > report.txt

This assumes you are in the directory where the file FindPst.vbs is saved.
Otherwise specify the full path. The //nologo option suppresses logo
information. The file report.txt is created in the current directory.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

Show quote
"LMac" <L***@discussions.microsoft.com> wrote in message
news:0C2F0A09-DD34-43CA-B632-C9E7C5933E08@microsoft.com...
> Hi
>
> I need to output a list of pst files from a server into a text file.  I
> have
> found this script which will show on screen the files but unable to find
> out
> how to export the list to a txt file.  Can this be done?
>
> Thanks
>
> ----------------------------------------------------
> Option Explicit
>
> Dim fso, objF, d, dc
> Dim objWMIService, colFiles, objFile
> Dim FileSizeKB, FileSizeMB, FileSizeGB
>
> Set objWMIService = _
> GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
>
> Set fso = CreateObject("Scripting.FileSystemObject")
>
> 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')")
> 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"
> ElseIf FileSizeMB >= 1 Then
> Wscript.Echo objFile.Name & " " & FileSizeMB & " MBytes"
> ElseIf FileSizeKB >= 1 Then
> Wscript.Echo objFile.Name & " " & FileSizeKB & " KBytes"
> Else
> Wscript.Echo objFile.Name & " " & objFile.FileSize & " Bytes"
> End If
>
> Next
>
> end if
>
> Next
>
Author
21 Nov 2007 3:25 PM
LMac
Thanks for the info.

Also, Is it possible to run this script for a number of servers and output
the info into one file run through a scheduled task.  I would be looking to
search a specific location for each server e.g.
\\servera\users
\\serverb\users
\\serverc\users
Or would it be better running a different scheduled task on each server
outputting to a different file each time?

Show quote
"Richard Mueller [MVP]" wrote:

> Run the script at a command prompt with the cscript host and redirect the
> output to a text file. For example if the script is called FindPst.vbs:
>
> cscript //nologo FindPst.vbs > report.txt
>
> This assumes you are in the directory where the file FindPst.vbs is saved.
> Otherwise specify the full path. The //nologo option suppresses logo
> information. The file report.txt is created in the current directory.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "LMac" <L***@discussions.microsoft.com> wrote in message
> news:0C2F0A09-DD34-43CA-B632-C9E7C5933E08@microsoft.com...
> > Hi
> >
> > I need to output a list of pst files from a server into a text file.  I
> > have
> > found this script which will show on screen the files but unable to find
> > out
> > how to export the list to a txt file.  Can this be done?
> >
> > Thanks
> >
> > ----------------------------------------------------
> > Option Explicit
> >
> > Dim fso, objF, d, dc
> > Dim objWMIService, colFiles, objFile
> > Dim FileSizeKB, FileSizeMB, FileSizeGB
> >
> > Set objWMIService = _
> > GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
> >
> > Set fso = CreateObject("Scripting.FileSystemObject")
> >
> > 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')")
> > 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"
> > ElseIf FileSizeMB >= 1 Then
> > Wscript.Echo objFile.Name & " " & FileSizeMB & " MBytes"
> > ElseIf FileSizeKB >= 1 Then
> > Wscript.Echo objFile.Name & " " & FileSizeKB & " KBytes"
> > Else
> > Wscript.Echo objFile.Name & " " & objFile.FileSize & " Bytes"
> > End If
> >
> > Next
> >
> > end if
> >
> > Next
> >
>
>
>
Author
21 Nov 2007 5:03 PM
Richard Mueller [MVP]
The script you posted is designed to be run on the local computer. The
statement:

Set objWMIService = _
GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

connects to the local computer. The "\\." in the path means to default to
the local computer. If you substitute the NetBIOS name of a computer (local
or remote) for the".", the script will connect to that computer (if you have
permissions and connectivity). You can run your script in a loop, once for
each computer in an array. Something similar to (watch line wrappting):
============
arrServers = Array("servera", "serverb", "serverc")

For Each strServer In arrServers
    ' code for each server.
    ' ...
    Set objWMIService = _
        GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strServer
& "\root\cimv2")
    ' ...
Next
===========
However, the code in your script that retrieves drives will only work on the
local computer. The FileSystemObject cannot retrieve drives on the remote
computer. Instead you can use the WMI Win32_LogicalDisk class. See the link
for details and examples:

http://www.microsoft.com/technet/scriptcenter/guide/sas_fsd_zinq.mspx

You can navigate in the TOC at the left for examples. You will need to use
the Win32_LogicalDisk class to enumerate all drives (of DriveType=3, which
is local hard disks), then for each drive use your code to look just at
files with the specified extension. The same objWMIService object reference
is used to retrieve the drives and also the files.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

Show quote
"LMac" <L***@discussions.microsoft.com> wrote in message
news:70A0565B-F96F-462E-8394-28D447EFCC96@microsoft.com...
> Thanks for the info.
>
> Also, Is it possible to run this script for a number of servers and output
> the info into one file run through a scheduled task.  I would be looking
> to
> search a specific location for each server e.g.
> \\servera\users
> \\serverb\users
> \\serverc\users
> Or would it be better running a different scheduled task on each server
> outputting to a different file each time?
>
> "Richard Mueller [MVP]" wrote:
>
>> Run the script at a command prompt with the cscript host and redirect the
>> output to a text file. For example if the script is called FindPst.vbs:
>>
>> cscript //nologo FindPst.vbs > report.txt
>>
>> This assumes you are in the directory where the file FindPst.vbs is
>> saved.
>> Otherwise specify the full path. The //nologo option suppresses logo
>> information. The file report.txt is created in the current directory.
>>
>> --
>> Richard Mueller
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>> "LMac" <L***@discussions.microsoft.com> wrote in message
>> news:0C2F0A09-DD34-43CA-B632-C9E7C5933E08@microsoft.com...
>> > Hi
>> >
>> > I need to output a list of pst files from a server into a text file.  I
>> > have
>> > found this script which will show on screen the files but unable to
>> > find
>> > out
>> > how to export the list to a txt file.  Can this be done?
>> >
>> > Thanks
>> >
>> > ----------------------------------------------------
>> > Option Explicit
>> >
>> > Dim fso, objF, d, dc
>> > Dim objWMIService, colFiles, objFile
>> > Dim FileSizeKB, FileSizeMB, FileSizeGB
>> >
>> > Set objWMIService = _
>> > GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
>> >
>> > Set fso = CreateObject("Scripting.FileSystemObject")
>> >
>> > 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')")
>> > 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"
>> > ElseIf FileSizeMB >= 1 Then
>> > Wscript.Echo objFile.Name & " " & FileSizeMB & " MBytes"
>> > ElseIf FileSizeKB >= 1 Then
>> > Wscript.Echo objFile.Name & " " & FileSizeKB & " KBytes"
>> > Else
>> > Wscript.Echo objFile.Name & " " & objFile.FileSize & " Bytes"
>> > End If
>> >
>> > Next
>> >
>> > end if
>> >
>> > Next
>> >
>>
>>
>>
Author
29 Nov 2007 11:09 AM
LMac
How would I run this as a scheduled task?

cscript //nologo FindPst.vbs > report.txt


Show quote
"LMac" wrote:

> Thanks for the info.
>
> Also, Is it possible to run this script for a number of servers and output
> the info into one file run through a scheduled task.  I would be looking to
> search a specific location for each server e.g.
> \\servera\users
> \\serverb\users
> \\serverc\users
> Or would it be better running a different scheduled task on each server
> outputting to a different file each time?
>
> "Richard Mueller [MVP]" wrote:
>
> > Run the script at a command prompt with the cscript host and redirect the
> > output to a text file. For example if the script is called FindPst.vbs:
> >
> > cscript //nologo FindPst.vbs > report.txt
> >
> > This assumes you are in the directory where the file FindPst.vbs is saved.
> > Otherwise specify the full path. The //nologo option suppresses logo
> > information. The file report.txt is created in the current directory.
> >
> > --
> > Richard Mueller
> > Microsoft MVP Scripting and ADSI
> > Hilltop Lab - http://www.rlmueller.net
> > --
> >
> > "LMac" <L***@discussions.microsoft.com> wrote in message
> > news:0C2F0A09-DD34-43CA-B632-C9E7C5933E08@microsoft.com...
> > > Hi
> > >
> > > I need to output a list of pst files from a server into a text file.  I
> > > have
> > > found this script which will show on screen the files but unable to find
> > > out
> > > how to export the list to a txt file.  Can this be done?
> > >
> > > Thanks
> > >
> > > ----------------------------------------------------
> > > Option Explicit
> > >
> > > Dim fso, objF, d, dc
> > > Dim objWMIService, colFiles, objFile
> > > Dim FileSizeKB, FileSizeMB, FileSizeGB
> > >
> > > Set objWMIService = _
> > > GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
> > >
> > > Set fso = CreateObject("Scripting.FileSystemObject")
> > >
> > > 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')")
> > > 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"
> > > ElseIf FileSizeMB >= 1 Then
> > > Wscript.Echo objFile.Name & " " & FileSizeMB & " MBytes"
> > > ElseIf FileSizeKB >= 1 Then
> > > Wscript.Echo objFile.Name & " " & FileSizeKB & " KBytes"
> > > Else
> > > Wscript.Echo objFile.Name & " " & objFile.FileSize & " Bytes"
> > > End If
> > >
> > > Next
> > >
> > > end if
> > >
> > > Next
> > >
> >
> >
> >

AddThis Social Bookmark Button