I have this script that for some reason everytime I try to add the size of the file the output comes out at the end of the file or the name of the variable displays rather than the size of the file. Can someone help here is my script. Out of frustration I removed the object.filesize out because it is not working correctly. I would also like to know how to add MB at the end of the number and if it rolls over to a gigabyte size how to tell it to add GB at the end. ANy help would be appreciated, thanks.
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery ("Select * From CIM_DataFile where Extension = 'pdf'")
dim filePath
For Each objFile in colFiles
filePath = objFile.Drive & objFile.Path & objFile.FileName & "." & objFile.Extension
Wscript.Echo "FilePath: " & filePath
GetFileOwner objFile.Drive & objFile.Path & objFile.FileName & "." & objFile.Extension
Wscript.Echo
Next
sub GetFileOwner(strFile)
dim owners
Set colItems = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" & strFile & "'}" _
& " WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")
For Each objItem in colItems
owners = owners & objItem.AccountName & ";"
Wscript.Echo "FileOwner: " & owners
Next
end sub
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery ("Select * From CIM_DataFile where Extension = 'pdf'")
dim filePath
For Each objFile in colFiles
filePath = objFile.Drive & objFile.Path & objFile.FileName & "." & objFile.Extension
Wscript.Echo "FilePath: " & filePath
GetFileOwner objFile.Drive & objFile.Path & objFile.FileName & "." & objFile.Extension
Wscript.Echo
Next
sub GetFileOwner(strFile)
dim owners
Set colItems = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" & strFile & "'}" _
& " WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")
For Each objItem in colItems
owners = owners & objItem.AccountName & ";"
Wscript.Echo "FileOwner: " & owners
Next
end sub