简体   繁体   English

如何使用Invoke-Command运行此PowerShell命令?

[英]How to run this PowerShell command with Invoke-Command?

I want to run the following PowerShell command on remote site 我想在远程站点上运行以下PowerShell命令

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: 如果在目标服务器上设置了winRM,则可以从头开始在Get-CimInstance中传递ComputerName参数:

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

Same with Get-Counter: 与Get-Counter相同:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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