启用 powershell remoting
https://blog.51cto.com/qicheng0211/1926913
https://helpcenter.gsx.com/hc/en-us/articles/202447926-How-to-Configure-Windows-Remote-PowerShell-Access-for-Non-Privileged-User-Accounts
https://4sysops.com/archives/powershell-remoting-without-administrator-rights/
https://helpcenter.gsx.com/hc/en-us/articles/202447926-How-to-Configure-Windows-Remote-PowerShell-Access-for-Non-Privileged-User-Accounts
- 启用远程服务
执行
``` Enable-PSRemoting -Force -SkipNetworkProfileCheck``` 。如果提示无法检查防火墙的状态。那么需要登录到 administrator 账号下执行一次执行
``` Test-WsMan``` 检测是否已启用 - 如果非管理员账号无法访问
服务端执行
``` Set-PSSessionConfiguration -Name Microsoft.PowerShell -showSecurityDescriptorUI``` 将需要的用户添加进列表也可以执行
``` net localgroup "Remote Management Users" /add user ```执行
``` Get-PSSessionConfiguration``` 查看当前允许访问的用户 - 调用
# 测试远程主机 test-wsman -computername 192.168.10.84 # 允许访问远程主机 Set-item wsman:localhost\client\trustedhosts –value * Set-item wsman:localhost\client\trustedhosts –value 192.168.10.* gci wsman::localhost\client\trustedhosts # 查看当前允许的远程主机 # 进入远程主机 , 使用 exit 退出 Enter-PSSession -ComputerName 192.168.10.84 -Credential admin $pSSession = New-PSSession -ComputerName $address -Credential admin $securePass = convertto-securestring -AsPlainText -Force -String $pass $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $user, $securePass # 创建连接对象 $opt = New-PSSessionOption -OpenTimeout 15000 $pSSession = New-PSSession -ComputerName $address -Credential $cred -Port $port -SessionOption $opt # 释放连接对象 Remove-PSSession $pSSession # 返回所有链接对象 Get-PSSession # 执行命令 Invoke-Command -Session(-ComputerName ) -command/-ScriptBlock # 要执行的命令 -FilePath # 要执行的脚本 -AsJob # 以 job 方式运行 -ThrottleLimit # 最大并发数, 默认 32 # 复制文件 Invoke-Command -Session $session -ScriptBlock { [System.Environment]::GetFolderPath('desktop') } # 获取对方的桌面路径 Copy-Item -FromSession $b C:\Programs\temp\test.txt -Destination C:\Programs\temp\test.txt Copy-Item -ToSession $session -Path 'C:\Users\xu\Desktop\启用 powershell remoting.md' -Destinatio 'c:\Users\admin\Desktop\test.md '