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

时间:2017-03-14 10:24:25

标签: powershell command invoke remote-server

我想在远程站点上运行以下PowerShell命令

Get-CimInstance -ClassName Win32_OperatingSystem | select csname, lastbootuptime

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

那是这样的调用命令格式吗?

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

1 个答案:

答案 0 :(得分:0)

如果在目标上设置了winRM,则可以从头开始在Get-CimInstance中传递ComputerName参数:

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

与Get-Counter相同:

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