Robert Perez-Corona
asked on
PoSh function to get CPU utilization from remote machine
I have a one-liner I need to turn into a function so that I can run against any machine on my AD domain/network. For example, instead of modifying the computername parameter and running the line can I execute something like:
Get-CPU -computername MYREMOTESERVER
Get-WmiObject -computername MYREMOTESERVER win32_processor | Measure-Object -property LoadPercentage -Average | Select Average
Thank you in advance
Get-CPU -computername MYREMOTESERVER
Get-WmiObject -computername MYREMOTESERVER win32_processor | Measure-Object -property LoadPercentage -Average | Select Average
Thank you in advance
We want to stay with the common naming conventions, Jose, and the asker correctly asked for a parameter ComputerName, so $remoteserver should be replaced by $ComputerName.
Also the process technique is oversized here, and even counterproductive as it will not allow proper pipeline processing of the result.
I think a much simpler approach is much better here
Also the process technique is oversized here, and even counterproductive as it will not allow proper pipeline processing of the result.
I think a much simpler approach is much better here
function Get-CPU ([String] $ComputerName = $env:ComputerName)
{
Get-WmiObject -computername $ComputerName win32_processor | Measure-Object -property LoadPercentage -Average | Select Average
}
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
I agree that is much better - and contains the respective computername in the output, which is missing from the former suggestions ;-).
ASKER
thank you all
Open in new window