Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

WMI Question re searching

$
0
0

Hello

If I am looking for files on a remote computer where PowerShell is not installed I some times use the CIM_DATAFILE class. For example the following query I put together will search a computer for any files whose extension is .cmd which is either on the C: or E: drive (but not any other drive), and which is not more than one directory deep i.e. C:\temp\ernie.cmd but not c:\temp\temp\ernie.cmd or deeper.

Get-WmiObject -Query "select * from cim_datafile where (extension = 'cmd' and (drive = 'E:' or drive = 'C:')) and (not path like '\\%\\%\\%')"

now this works fine, but what I find is if one of the drive letters does not exist say E: in this case the query returns no data (event though there is a genuine match on C:)

So lets say I have an E: and a C: drive on a computer, the query returns the data correctly as above, if I run the same query but change say the E: drive in the query to J: which does not exist on the computer, the query returns no data i.e. not informing you of the files on C: Now I could build up part of the query as a string first using WIN32_LogicalDisk so I am only checking the fixed drives that do exist, but wondered if anyone had seen this behaviour and had a solution?

Thanks All

Ernie


Viewing all articles
Browse latest Browse all 8583

Trending Articles