博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在远程机器上跑PowerShell脚本
阅读量:4703 次
发布时间:2019-06-10

本文共 1451 字,大约阅读时间需要 4 分钟。

当我们需要在远程机器上跑一些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

 

 

 

 

转载于:https://www.cnblogs.com/lilideng/archive/2012/11/20/Run_PowerShell_Remotely.html

你可能感兴趣的文章
怎么用MindManager记笔记
查看>>
xargs命令
查看>>
java程序设计课程实验报告1
查看>>
密码的三重属性
查看>>
191. Number of 1 Bits
查看>>
通过划分的方式在线性时间内找出一个序列中第K大的元素
查看>>
用一段代码去了解函数的结构
查看>>
HDFS源码分析数据块复制选取复制源节点
查看>>
java线程池(一)
查看>>
Sublime插件安装
查看>>
Spring主从数据源动态切换
查看>>
JUnit 4在Eclipse中的使用
查看>>
在DOS命令中输入ipconfig /all,出现“该命令不是系统内部命令......”
查看>>
Django中的CSRF
查看>>
百度地图API 绘制轨迹历史
查看>>
jssdk微信图片上传功能
查看>>
c++学习02——queue
查看>>
tensorflow-1day入门
查看>>
spring boot-- 三种启动方式
查看>>
Dm8168 多核通信
查看>>