Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


search file extension

 
Logged in as: Guest
arrSession:exec spGetSession 2,5,63481
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Windows PowerShell >> search file extension
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 search file extension - 8/15/2008 12:38:01 AM   
  butcha33

 

Posts: 6
Score: 0
Joined: 8/15/2008
Status: offline
Hi, i am having problem with this script. It works perfect on my local machine and all remote machines but only on the C drive! If i try to search for a *.mp3 on any other partition other than C it fails with this error message. New to scripting so your help will be appreciated

cheers

Butcha

Line 45
Char 1
The Remote Procedure Call Failed
800706BE
Source (null)

'on error resume next

servername = InputBox ("Enter Machine Name" & (Chr(13) & Chr(10)) & "Example: dc-live-it028 ", "My Audit by Shieraz B")
If servername = "" then
WScript.quit
end if
drive = InputBox ("Enter Drive Letter" & (Chr(13) & Chr(10)) & "Example: C / D  (Case sensitive)", "My Audit by Shieraz B")
If drive = "" then
WScript.quit
end if
strExtension = InputBox ("Enter File Extension" & (Chr(13) & Chr(10)) & "Example: mp3", "My Audit by Shieraz B")
If strExtension = "" then
WScript.quit
end if
strDrive = drive & ":"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
x = 2
objExcel.Cells(1, 1).Value = "File Name"
objExcel.Cells(1, 2).Value = "File Size"
objExcel.Cells(1, 3).Value = "Path (" & servername & " " & strDrive & ")"
objExcel.Cells(1, 4).Value = "Creation Date"
objExcel.Cells(1, 5).Value = "Last Accessed"

objExcel.Range("A1:E1").Select
objExcel.Selection.Interior.ColorIndex = 15
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit

Set objWMIService = GetObject("winmgmts:\\" & servername & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile Where Drive = '" & strDrive & "' And Extension = '" & strExtension & "'")
For Each objItem in colFiles
objExcel.Cells(x, 1).Value = objItem.FileName
objExcel.Cells(x, 2).Value = FormatNumber(objItem.FileSize/1024/1024,1) & " MB"
objExcel.Cells(x, 3).Value = objItem.Path
objExcel.Cells(x, 4).Value = ConvWbemTime(objItem.CreationDate)
objExcel.Cells(x, 5).Value = ConvWbemTime(objItem.LastAccessed)
x = x + 1
Next
Function ConvWbemTime(IntervalFormat)
sMonth = mid(IntervalFormat,5,2)
sDay = mid(IntervalFormat,7,2)
sYear = mid(IntervalFormat,1,4)
sHour = mid(IntervalFormat,9,2)
sMinutes = mid(IntervalFormat,11,2)
sSeconds = mid(IntervalFormat,13,2)
ConvWbemTime = sMonth & "-" & sDay & "-" & sYear & " " & sHour & ":" & sMinutes & ":" & sSeconds
End Function

objExcel.Range("A1:E1").Select
objExcel.Selection.Interior.ColorIndex = 15
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit

Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
Set objRange = objExcel.Range("A2")
objRange.Sort objRange,1,,,,,,1

objExcel.Cells(x, 1).Font.Bold = TRUE
objExcel.Cells(x, 1).Font.Size = 10
objExcel.Cells(x, 1).Value = "Search Completed, Save the spreadsheet!"

'MsgBox "Done"
 
 
Post #: 1
 
 RE: search file extension - 8/15/2008 4:15:37 AM   
  turranx


Posts: 42
Score: 0
Joined: 2/7/2006
Status: offline
This is not a Powershell Script.  Please re-post in the 'WSH & Client Side VBScript" section of this forum.

Which line is 45?  When I look for 45, I get "sYear = mid(IntervalFormat,1,4)".  The error your reporting doesn't make sense for this line of code.  I'm thinking your line 45 is different from mine.

I tried it on my own workstation.  It worked fine for every drive letter I chose; including those that didn't exist (B:\).  My suggestion to you is to start using MSE7.exe and start stepping through your code line by line.  The error might occur on line 45 but be caused by something a few lines earlier.

< Message edited by turranx -- 8/15/2008 4:42:52 AM >


_____________________________

Microsoft Windows 2000 Scripting Guide - The best book for newbie scripters
http://www.myspace.com/Evil__Overlord

(in reply to butcha33)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Windows PowerShell >> search file extension Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts