首页 > 解决方案 > 是否可以在远程计算机上运行 Powershell 脚本?

问题描述

我希望对同一网络中存在的节点运行“IE Rest Script”。

脚本存在于 中,MachineA并且应该在MachineB存在于同一网络中的 中执行。

脚本:

add-type -AssemblyName System.Windows.Forms
add-type -AssemblyName microsoft.visualbasic

RunDll32.exe InetCpl.cpl,ResetIEtoDefaults

[Microsoft.VisualBasic.Interaction]::AppActivate("rundll32")
[System.Windows.Forms.SendKeys]::SendWait("{tab}")
[System.Windows.Forms.SendKeys]::SendWait(" ")
[System.Windows.Forms.SendKeys]::SendWait("r")
[System.Windows.Forms.SendKeys]::SendWait("c")

taskkill.exe /f /im iexplore.exe`

标签: powershellpowershell-remoting

解决方案


是的:

Invoke-Command -ComputerName myremotehost.mydomain.tld -ScriptBlock {
    # This code here runs on the remote system
}

您必须确保在目标系统上激活了PowerShell Remoting 。


推荐阅读