<anthony.schemel@xxxxxx> wrote in message
news:892c7529-1883-47a2-99b3-205b942f39c5@xxxxxx
> Hi guys
>
> I need to list all the PST files on a server and for convenience put
> them in a CSV or TXT file. I need their locations as well. Now, I
> have run a few scripts to get this done but get errors when running
> them. The strange thing is that it runs perfectly on my own PC.
>
> The first one gives me a 'Remote Procedure Call' error and the code is
> as follows:
>
> Dim fso, NewFile
>
> Set fso = CreateObject("Scripting.FileSystemObject")
>
> strComputer = "00172FPSJNB0007"
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}\\" & strComputer & "\root
> \cimv2")
>
> Set colFiles = objWMIService.ExecQuery _
> ("Select Name from CIM_DataFile" _
> & " where Drive='d:' and Extension='pst'")
>
> Set NewFile = fso.CreateTextFile("c:00172FPSJNB0007.csv", True)
>
> For Each objFile in colFiles
> NewFile.WriteLine strOffset & objFile.Name
> Next
>
> NewFile.close
>
> Wscript.Echo "Done."
> Wscript.Quit
>
> Now, the next one actually lists all files on the PC. That is fine
> because one can actually then afterwards pick out the details you are
> looking for. After it generates about a 1000 entries in the CSV file
> it through out an error:
>
> Dim sFolder, fso, NewFile
>
> strComputer = "00172FPSJNB0007"
> Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
> \cimv2")
>
> Set fso = CreateObject("Scripting.FileSystemObject")
>
> strFolderName = "d:\users"
>
> Set colSubfolders = objWMIService.ExecQuery _
> ("Associators of {Win32_Directory.Name='" & strFolderName & "'} "
> _
> & "Where AssocClass = Win32_Subdirectory " _
> & "ResultRole = PartComponent")
>
> arrFolderPath = Split(strFolderName, "\")
> strNewPath = ""
> For i = 1 to Ubound(arrFolderPath)
> strNewPath = strNewPath & "\\" & arrFolderPath(i)
> Next
> strPath = strNewPath & "\\"
>
> Set colFiles = objWMIService.ExecQuery _
> ("Select * from CIM_DataFile where Path = '" & strPath & "'")
>
> Set NewFile = fso.CreateTextFile("c:00172FPSJNB0007a.csv", True)
>
> For Each objFile in colFiles
> NewFile.WriteLine strOffset & objFile.Name
> Next
>
> For Each objFolder in colSubfolders
> GetSubFolders strFolderName
> Next
>
> Sub GetSubFolders(strFolderName)
> On Error Resume Next
> Set colSubfolders2 = objWMIService.ExecQuery _
> ("Associators of {Win32_Directory.Name='" & strFolderName &
> "'} " _
> & "Where AssocClass = Win32_Subdirectory " _
> & "ResultRole = PartComponent")
>
> For Each objFolder2 in colSubfolders2
> strFolderName = objFolder2.Name
> arrFolderPath = Split(strFolderName, "\")
> strNewPath = ""
> For i = 1 to Ubound(arrFolderPath)
> strNewPath = strNewPath & "\\" & arrFolderPath(i)
> Next
> strPath = strNewPath & "\\"
>
> Set colFiles = objWMIService.ExecQuery _
> ("Select * from CIM_DataFile where Path = '" & strPath &
> "'")
>
> For Each objFile in colFiles
> NewFile.WriteLine strOffset & objFile.Name
> Next
>
> GetSubFolders strFolderName
> Next
> On Error GoTo 0
> End Sub
>
> Wscript.Echo "Done"
>
> Any ideas guys? Seeing that this is a standard maintenance task for which
there are standard maintenance tools, I would take the
easy way out and type this command:
dir /s /b \\00172FPSJNB0007\d$\*.pst > c:\PSTFiles.txt
Very fast to write, easy to maintain and fast to execute.