PowerShell 相关常用命令(update...)
# PowerShell提示系统禁止执行脚本解决方法(报错提示)
## 获得当前的执行策略
Get-executionpolicy
>> Bypass 策略完全不限制
>> Restricted 策略不允许任何脚本运行
>> AllSigned 可以运行脚本,但要求所有脚本和配置文件由可信发布者签名,包括在本地计算机上编写的脚本。
>> RemoteSigned 可以运行脚本,但要求从网络上下载的脚本和配置文件由可信发布者签名; 不要求对已经运行和已在本地计算机编写的脚本进行数字签名。
>> Unrestricted 可以运行未签名脚本。(危险!)
>> Undefined 表示运行级别尚未定义。但此时实际是执行上面提到的系统默认运行级别。
## 修改当前执行策略
Set-ExecutionPolicy RemoteSigned (管理员方式执行Powershell)
【远程相关】
## 查看TrustedHost列表
gci wsman::localhost\client\trustedhosts
## 添加TrustedHost列表
Set-item wsman:localhost\client\trustedhosts –value * # 允许自己访问所有
Set-item wsman:localhost\client\trustedhosts –value sever1,server2 # 允许自己访问别人de计算机名
Set-item wsman:localhost\client\trustedhosts –value *.testj.com # 允许自己访问的域名
Set-item wsman:localhost\client\trustedhosts –value 192.168.X.X # 允许自己访问的IP地址
PS:如果自己谁都不允许
Set-item wsman:localhost\client\trustedhosts –value -
# 远程其他电脑的PS
需要开启端口:5985
Enable-PSremoting/Disable-PSremoting # 启动允许PS远程,且网络位置不能被设置为public,因为Windows 防火墙例外不能在网络位置是public时被启用。
test-wsman -computername localhost # 测试服务器上的WINRM服务是否在运行
Enter-PSSession X.X.X.X -Credential administrator # 远程X.X.X.X 电脑的PS
## 关闭PS远程
Disable-PSremoting # 关闭
Set-Service winrm -StartupType Manual # 服务设置为手动
Stop-Service winrm # 停止服务
# 移除默认情况下WinRM在5985端口设置的监听器
Get-ChildItem WSMan:\localhost\Listener –Recurse | Foreach-Object { $_.PSPath } | Where-Object { (Get-Item "$_\Port").Value -eq 5985 } | Remove-Item
## 查看WinRM正在侦听的特定IP:
winrm enumerate winrm/config/listener Or winrm e winrm/config/listener
## 修改WinRM端口
WinRM默认的http端口是5985,https端口5986
winrm set winrm/config/listener?Address=+Transport=HTTP ‘@{Port=“1212”}’
或 set-item wsman:\localhost\listener\listener\port 1212
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库