能够针对Microsoft.PowerShell
(5.1)执行此操作,但今天我在 5.1 上遇到了一个已知问题,Copy-Item
因此我在远程服务器上安装了 PowerShell 7(在安装程序中选中“启用远程处理”)并试图让它工作。
$securePassword = ConvertTo-SecureString -AsPlainText -Force -String $Password
$credential = New-Object -TypeName system.management.automation.pscredential -ArgumentList $Username, $securePassword
$session = New-PSSession $targetMachineHostName -Credential $credential -ConfigurationName "Microsoft.PowerShell"
Enter-PSSession $session
以上作品。但是,如果我将 ConfigurationName 更改为 "PowerShell.7.1.0"
我得到:
[myserver.com.au] Connecting to remote server myserver.com.au failed with
| the following error message : <f:WSManFault
| xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault" Code="2689860592"
| Machine="myserver.com.au"><f:Message><f:ProviderFault provider="PowerShell.7.1.0"
| path="C:\Windows\system32\PowerShell\7.1.0\pwrshplugin.dll"></f:ProviderFault></f:Message></f:WSManFault> For more information, see the about_Remote_Troubleshooting Help topic.
在远程服务器上,我在 7.1 powershell 中运行了 enable ps remoting 所以如果我运行Get-PSSessionConfiguration
它会返回一堆配置,包括以下内容:
Name : PowerShell.7.1.0
PSVersion : 7.1
StartupScript :
RunAsUser :
Permission : NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators AccessAllowed, BUILTIN\Remote
Management Users AccessAllowed
错误所指的dll存在于机器上。
我使用的用户凭据适用于远程计算机上的本地用户,该用户不是管理员,但属于该Remote Management Users
组。
另外值得注意的是远程机器本身(作为不同的管理员本地帐户,我可以启动一个会话localhost
)。