Windows powerShell远程连接服务器

Windows powerShell远程连接服务器,需要设置以下3个步骤:

1、在服务器端添加信任的客户端地址(客户端的IP地址)

    通过winrm命令配置:

 这里host1,2,3可以填你所在的客户端机器的ip或者主机名

  winrm set winrm/config/client @{TrustedHosts="host1, host2, host3"}

2、在客户端添加信任主机

    在客户端以管理员打开Windows powerShell;

    (1)、通过“enable-psremoting”命令将winrm更新为接收请求

    (2)、添加信任主机:

              #1.切到远程管理的client目录下

                    cd WSMan::localhost\client               

                #2.将192.168.1.135添加为可信主机

                    Set-Item ./TrustedHosts 192.168.1.135

3、连接远程服务器:

     通过以下命令连接

$uname="admin" #administrator为用户名
         $pwd=ConvertTo-SecureString "nmczqk" -AsPlainText -Force; #nmczqk为密码
         $cred=New-Object System.Management.Automation.PSCredential($uname,$pwd); #创建自动认证对象
         $pcname="10.28.17.37"

         Enter-PSSession -ComputerName $pcname -Credential $cred #登录

4、注意   

Powershell Remoting依赖于WinRM (Windows Remote Management)在远程机器上运行操作。默认情况下,WinRM为每一个Powershell远程连接分配了最大(MaxMemoryPerShellMB=1024)1G的内存空间(早期的版本号仅仅有150M),用于运行远程操作。

但远程操作所需的运行内存空间 > 1G时,就会出现了内存不足的问题,不同的操作可能表现会有所不同,如:有的会抛出OutOfMemoryException等。针对这个问题。解决的办法就是添加MaxMemoryPerShellMB,然后重新启动WinRM服务:

$maxMemoryPerShellVM = 3072

Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB $maxMemoryPerShellVM

Set-Item WSMan:\localhost\Plugin\Microsoft.PowerShell\Quotas\MaxMemoryPerShellMB $maxMemoryPerShellVM

Write-Output "List MaxMemoryPerShellMB configuration"

# Restart WinRM service to make the change take effect

Restart-Service winrm 






  
  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值