【问题标题】:How to run this PowerShell command with Invoke-Command?如何使用 Invoke-Command 运行这个 PowerShell 命令?
【发布时间】:2017-08-04 15:13:25
【问题描述】:

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

Get-CimInstance -ClassName Win32_OperatingSystem | select csname, lastbootuptime

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

是这样的invoke命令格式吗?

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

【问题讨论】:

  • 那是什么问题,这看起来有效

标签: powershell command invoke remote-server


【解决方案1】:

如果目标上设置了 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-21
    • 2022-12-02
    • 2020-01-27
    • 2021-02-24
    • 1970-01-01
    相关资源
    最近更新 更多