0

I have several Windows machines and I am trying to ps remote into each one to run a command that will scan the entire host for specific file types while also tell me where they are located. So far, I've have the following command which work on most of them:

 Get-WMIObject Win32_LogicalDisk -filter 'DriveType = 3' | Select-Object DeviceID | ForEach-Object {Get-Childitem -force -ErrorAction Ignore -include *.p12,*.pfx -recurse}

I get the output I expect to see on most:

Directory: C:\ ... 

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         5/17/2021  10:14 AM           206 $example.pfx

but this one has me puzzled:

Get-WMIObject : Call cancelled
At line:1 char:1
+ Get-WMIObject Win32_LogicalDisk -filter 'DriveType = 3' | Select-Obje ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Is this referring to a timeout of the command? The machine I am scanning that results with this has a fairly large amount of files, so I'm not surprised if this is the case...

If so, is there some way to outlast the timer?

doggo_star
  • 11
  • 1
  • 3
  • I would guess a problem with WMI on that machine. See https://social.technet.microsoft.com/Forums/windows/en-US/9bea0afc-dfc9-45dd-acec-f680fc377847/getwmiobject-cmdlet-failing-with-an-invalidoperation-error?forum=winserverpowershell – zdan May 19 '21 at 23:34
  • as an alternative, this >>> `Get-PSDrive -PSProvider FileSystem | Where-Object -Property used -gt 0` <<< will give you a list of local drives. then you could use the `CIM_LogicalFile` class to grab the files you want. – Lee_Dailey May 19 '21 at 23:45
  • Cant you run a direct gci, or invoke a gci to it? – Abraham Zinala May 19 '21 at 23:52
  • @zdan I believe running the following command should have cleared any wmi issues I may have had: netsh advfirewall firewall set rule group="windows management instrumentation (wmi)" new enable=yes but I still have the above issue. – doggo_star May 21 '21 at 16:35

0 Answers0