简体   繁体   中英

How to run this PowerShell command with Invoke-Command?

I want to run the following PowerShell command on remote site

Get-CimInstance -ClassName Win32_OperatingSystem | select csname, lastbootuptime

and

Get-Counter -Counter "\memory\available mbytes" -MaxSamples 10 -SampleInterval 1

Is that the invoke command format like this?

Invoke-Command -ComputerName server01 {
    Get-CimInstance -ClassName Win32_OperatingSystem | select csname, lastbootuptime
}

If winRM is set up on the target, you can pass the ComputerName parameter in Get-CimInstance right from the start:

Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName server01| select csname, lastbootuptime

Same with Get-Counter:

Get-Counter -ComputerName server01 -Counter "\memory\available mbytes" -MaxSamples 10 -SampleInterval 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM