在远程机器上跑PowerShell脚本
2012-11-20 17:10
148 查看
当我们需要在远程机器上跑一些PowerShell命令或者文件的时候,可以运行以下命令
$secpassword = ConvertTo-SecureString "Password" -AsPlainText –Force
$mycreds = New-Object System.Management.Automation.PSCredential ("Username", $secpassword)
Enter-PSSession -ComputerName ComputerName -Credential $mycreds
你可能会遇到以下错误:
Enter-PSSession : Connecting to remote server failed with the following error message : The client cannot connect to th e destination specified in the request. Verify that the service on the destination is running and is accepting requests
. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or Win
RM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the
WinRM service: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:16
+ Enter-PSSession <<<< -ComputerName NEB-OM-336757.smx.net -Credential $mycreds
+ CategoryInfo : InvalidArgument: (ComputerName:String) [Enter-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed
因为你没有在远程机器上开启允许远程执行PowerShell命令导致了这个错误的出现。
你需要在远程机器上用管理员权限打开PowerShell控制台,执行命令Enable-PSRemoting –Force。
再执行以上命令界面就会出现,此时你就可以在这个控制台上输入命令执行远程操作了
[ComputerName]: PS C:\Users\asttest\Documents>
注意,这个Session直到PowerShell界面关闭,或者强制退出为止。比如运行Exit-PSSession
$secpassword = ConvertTo-SecureString "Password" -AsPlainText –Force
$mycreds = New-Object System.Management.Automation.PSCredential ("Username", $secpassword)
Enter-PSSession -ComputerName ComputerName -Credential $mycreds
你可能会遇到以下错误:
Enter-PSSession : Connecting to remote server failed with the following error message : The client cannot connect to th e destination specified in the request. Verify that the service on the destination is running and is accepting requests
. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or Win
RM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the
WinRM service: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:16
+ Enter-PSSession <<<< -ComputerName NEB-OM-336757.smx.net -Credential $mycreds
+ CategoryInfo : InvalidArgument: (ComputerName:String) [Enter-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed
因为你没有在远程机器上开启允许远程执行PowerShell命令导致了这个错误的出现。
你需要在远程机器上用管理员权限打开PowerShell控制台,执行命令Enable-PSRemoting –Force。
再执行以上命令界面就会出现,此时你就可以在这个控制台上输入命令执行远程操作了
[ComputerName]: PS C:\Users\asttest\Documents>
注意,这个Session直到PowerShell界面关闭,或者强制退出为止。比如运行Exit-PSSession
相关文章推荐
- 一键帮你复制多个文件到多个机器——PowerShell小脚本(内附PS远程执行命令问题解析)
- [5月29日的脚本] 检索远程机器上所有本地用户的账户信息 (PowerShell)
- PowerShell升级远程机器的windows service的脚本(最终版)
- PowerShell 2.0在远程主机上运行命令和脚本
- PowerShell 2.0在远程主机上运行命令和脚本
- 自动备份远程机器的脚本
- 设计一个脚本,监控远程的一台机器(假设ip为123.23.11.21)的存活状态,当发现宕机时发一封
- PowerShell 2.0在远程主机上运行命令和脚本
- 清除本地或远程机器日志的VBS脚本
- 使用PowerShell关闭远程机器上的进程
- Perl Net::openSSH 远程登录多台机器执行脚本
- [PowerShell]- 通过WMI连接远程机器并不提示输入密码
- 利用putty在windows上通过脚本在远程Linux机器执行指令
- Linux中使用expect脚本实现远程机器自动登录
- linux本机(192.168.99.11)登陆远程机器(192.168.99.77)shell脚本
- PowerShell远程执行脚本是如何引用外部参数
- python实现动态更新远程机器列表的SSH登录脚本
- Linux使用expect脚本实现远程机器自动登录
- Jenkins slave配置(实现持续集成中打包完成后执行远程机器的python脚本)
- 32. PowerShell -- 批处理中执行远程的powershell脚本的方法