PowerShell 7.3 - Problems with Retrieving CPU Usage on Remote Machines Using Get-WmiObject
I'm collaborating on a project where I'm having a hard time understanding I'm relatively new to this, so bear with me. I tried several approaches but none seem to work. I've searched everywhere and can't find a clear answer. I'm trying to monitor CPU usage on multiple remote machines using PowerShell 7.3. I've written a script to gather this information through `Get-WmiObject`, but I'm working with an scenario where the command hangs indefinitely when trying to connect to certain machines. Hereโs the code snippet Iโm using: ```powershell $computers = @('Server1', 'Server2', 'Server3') $results = foreach ($computer in $computers) { try { Get-WmiObject -Class Win32_Processor -ComputerName $computer -ErrorAction Stop | Select-Object Name, LoadPercentage } catch { Write-Host "behavior retrieving data from $computer: $_" -ForegroundColor Red } } $results ``` On some machines, this works perfectly, but on others, it just hangs at `Get-WmiObject` without any behavior messages. I've checked the WMI service on the remote machines, and itโs running correctly. I also verified that the necessary firewall ports are open for WMI requests. I even considered using `Get-CimInstance` as an alternative, but I ran into the same scenario. Hereโs how I tried it: ```powershell $results = foreach ($computer in $computers) { try { Get-CimInstance -ClassName Win32_Processor -ComputerName $computer -ErrorAction Stop | Select-Object Name, LoadPercentage } catch { Write-Host "behavior retrieving data from $computer: $_" -ForegroundColor Red } } ``` I still experience the hang scenario. Additionally, if I run `Test-Connection` to these machines before the WMI call, it shows that they are reachable. Is there a timeout option I can set for these commands, or is there another way to handle remote WMI queries more reliably? Any best practices for monitoring CPU usage remotely would be appreciated. For context: I'm using Powershell on Windows. Has anyone else encountered this? This is my first time working with Powershell 3.10. Any feedback is welcome! I recently upgraded to Powershell 3.9. Any advice would be much appreciated.