strComputer = "." ' use "." for local computer
strDrive = "c:"
strExtension = "pst"

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

Set colItems = objWMIService. _
ExecQuery("Select Name from CIM_DataFile" _
& " where Drive ='C:' and Extension='pst'")
'& " where '" & strDrive & "' & '" & strExtension & "'") - I would like
to use this but it will not work


'WScript.Echo "# of files found: " & colItems.Count
For Each objItem In colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "CIM_DataFile instance"
Wscript.Echo "-----------------------------------"
Wscript.Echo "FileName: " & objItem.Name
WScript.Echo "FileSize: " & objItem.size - I can not get the file saize

Next
Error - U:\Scripts\FindPST.vbs(33, 5) Microsoft VBScript runtime error:
Object doesn't support this property or method: 'objItem.size'

Please help

Re: Find PST On both c:\ and u:\ by Tom

Tom
Tue May 06 12:36:54 CDT 2008

On May 6, 1:09 pm, freddy <fre...@discussions.microsoft.com> wrote:
> strComputer = "." ' use "." for local computer
> strDrive = "c:"
> strExtension = "pst"
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>
> Set colItems = objWMIService. _
> ExecQuery("Select Name from CIM_DataFile" _
> & " where Drive ='C:' and Extension='pst'")
> '& " where '" & strDrive & "' & '" & strExtension & "'") - I would like
> to use this but it will not work
>
> 'WScript.Echo "# of files found: " & colItems.Count
> For Each objItem In colItems
> Wscript.Echo "-----------------------------------"
> Wscript.Echo "CIM_DataFile instance"
> Wscript.Echo "-----------------------------------"
> Wscript.Echo "FileName: " & objItem.Name
> WScript.Echo "FileSize: " & objItem.size - I can not get the file saize
>
> Next
> Error - U:\Scripts\FindPST.vbs(33, 5) Microsoft VBScript runtime error:
> Object doesn't support this property or method: 'objItem.size'
>
> Please help

Try ...

Set colItems = objWMIService. _
ExecQuery("Select Name from CIM_DataFile" _
& " where Drive ='" & strDrive & "' AND " _
& " Extension='" & strExtension & "'")

and ...

WScript.Echo "FileSize: " & objItem.Filesize

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

RE: Find PST On both c:\ and u:\ by urkec

urkec
Tue May 06 12:46:01 CDT 2008

"freddy" wrote:

>
> strComputer = "." ' use "." for local computer
> strDrive = "c:"
> strExtension = "pst"
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>
> Set colItems = objWMIService. _
> ExecQuery("Select Name from CIM_DataFile" _
> & " where Drive ='C:' and Extension='pst'")
> '& " where '" & strDrive & "' & '" & strExtension & "'") - I would like
> to use this but it will not work
>
>
> 'WScript.Echo "# of files found: " & colItems.Count
> For Each objItem In colItems
> Wscript.Echo "-----------------------------------"
> Wscript.Echo "CIM_DataFile instance"
> Wscript.Echo "-----------------------------------"
> Wscript.Echo "FileName: " & objItem.Name
> WScript.Echo "FileSize: " & objItem.size - I can not get the file saize
>
> Next
> Error - U:\Scripts\FindPST.vbs(33, 5) Microsoft VBScript runtime error:
> Object doesn't support this property or method: 'objItem.size'
>
> Please help


The property name is FileSize, not Size. You can include AND and OR
operators in the query:

strComputer = "."
strCDrive = "c:"
strUDrive = "u:"
strExtension = "pst"

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

Set colItems = objWMIService. _
ExecQuery("Select * From Cim_DataFile " _
& "Where (Drive ='" & strCDrive & "' " _
& "Or Drive = '" & strUDrive & "') " _
& "And Extension='" & strExtension & "'")

For Each objItem In colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "CIM_DataFile instance"
Wscript.Echo "-----------------------------------"
Wscript.Echo "FileName: " & objItem.Name
WScript.Echo "FileSize (bytes): " & objItem.FileSize
Next


--
urkec

Re: Find PST On both c:\ and u:\ by Pegasus

Pegasus
Tue May 06 15:35:50 CDT 2008


"freddy" <freddy@discussions.microsoft.com> wrote in message
news:EE0C79EE-845E-4FC8-9423-EFF35E0EAF35@microsoft.com...
>
> strComputer = "." ' use "." for local computer
> strDrive = "c:"
> strExtension = "pst"
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>
> Set colItems = objWMIService. _
> ExecQuery("Select Name from CIM_DataFile" _
> & " where Drive ='C:' and Extension='pst'")
> '& " where '" & strDrive & "' & '" & strExtension & "'") - I would like
> to use this but it will not work
>
>
> 'WScript.Echo "# of files found: " & colItems.Count
> For Each objItem In colItems
> Wscript.Echo "-----------------------------------"
> Wscript.Echo "CIM_DataFile instance"
> Wscript.Echo "-----------------------------------"
> Wscript.Echo "FileName: " & objItem.Name
> WScript.Echo "FileSize: " & objItem.size - I can not get the file
> saize
>
> Next
> Error - U:\Scripts\FindPST.vbs(33, 5) Microsoft VBScript runtime error:
> Object doesn't support this property or method: 'objItem.size'
>
> Please help

Using WMI to search for files is horribly slow - perhaps 100 times
slower than FSO if you search a whole partition. I would either use
a batch file solution or else the File System Object. This batch file
took 8 seconds to search my drive C:\ for .PST files:
================
@echo off
for /F "delims=" %%a in ('dir /b /s c:\*.pst') do call :Sub %%a
for /F "delims=" %%a in ('dir /b /s u:\*.pst') do call :Sub %%a
goto :eof

:Sub
for /F "tokens=4*" %%a in ('dir "%*" ^| find /i ".pst"') do echo %%a %*
================

This VB Script file took 29 seconds to do the same job:
================
Set objFSO = CreateObject("Scripting.FileSystemObject")
CheckFolder "C:\"
CheckFolder "U:\"

Sub CheckFolder (sWD)
Set objFolder = objFSO.GetFolder(sWD)
Set objFiles = objFolder.Files
For Each objFile In objFiles
If Right(UCase(objFile.Name), 4) = ".PST" Then
WScript.Echo objFile.Size & " " & sWD & objFile.Name
End If
Next

Set objFolders = objFolder.SubFolders
For Each objFolder In objFolders
CheckFolder(sWD & objFolder.Name & "\")
Next
End Sub

================