【转】Powershell与jenkins集成部署的运用(powershell运用)

powershell简介:

远程管理采用的一种新的通信协议,Web Services for Management,简称WS-MAN它通过http或者https进行工作,WS-WAN的实现主要基于一个后台服务:Windows远程管理(WinRM)。Server2008R2中默认开启该服务,从Server2012开始,该服务便集成在系统中默认开启,Win7默认安装此服务,但是默认为禁用状态,Win8,Win10默认开启。这种远程连接不会被客户端察觉到,也不会占用远程连接数!

powershell的简单运用:

启动方式:
powershell系统默认安装了,通过开始-运行-输入powershell,会弹出powershell的工作窗口,如图


设置服务器白名单:
命令: winrm set winrm/config/client ‘@{TrustedHosts=”*”}’


开启远程服务:
命令:winrm quickconfig
注意:powershell需要以管理员身份运行,否则会报错误码 -2144108526 0x80338012,如图。

 

更改为管理员身份运行,开启远程服务,如图。


连接远程服务:
命令:Enter-PSSession -ComputerName 【RemoteComputerName】 -Credential Ge【t-Credential】


输入连接服务器的密码,连接成功后会显示服务器的名字或者IP地址,如图


拷贝文件:
命令:Copy-Item -Path [文件地址] -Destination [目标文件地址] -ToSession $mySession -Recurse -Force

原文:https://blog.csdn.net/yunhua88/article/details/79034225

碰到的问题: 执行Enter-PSSession -ComputerName 【RemoteComputerName】 -Credential Ge【t-Credential】 时碰到以下问题。

解决办法:

设置防火墙

powershell 中运行

netsh advfirewall firewall set rule group="Windows 远程管理" new enable=yes

原文地址:https://www.cnblogs.com/keepSmile/p/10635560.html