远程主机执行powershell

1,需要再域环境中

2,需要用管理员权限运行powershell

  2.1,开启Enable-PSRemoting -Force -SkipNetworkProfileCheck

  2.2,开启set-executionpolicy remotesigned

3,执行代码

Invoke-Command -ComputerName [ServerName] -ScriptBlock {ipconfig}
4,{}中执行命令
5,本地传参
$Log = "PowerShellCore/Operational"
Invoke-Command -ComputerName Server01 -ScriptBlock {Get-WinEvent -LogName $Using:Log -MaxEvents 10}

 

 

posted @ 2021-10-21 17:10  A~你说啥?我听不见!  阅读(37)  评论(0)    收藏  举报