首页 > 解决方案 > 如何从 server1 执行 powershell 脚本以在 server2 中部署 wsp

问题描述

我正在尝试通过在 server1 中运行 powershell 脚本来远程部署 server2 中存在的 wsp 文件。

我能够使用以下命令通过 server1 成功登录到 server2:

$password = ConvertTo-SecureString "password" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential("username",$password)

但我无法部署 wsp 文件。这是我尝试过的代码:

Enter-PSSession -ComputerName server2 -Credential $cred
Add-PSSnapin Microsoft.Sharepoint.Powershell –EA 0
Update-SPSolution -Identity TechSoup.Web.wsp -LiteralPath "C:\Program Files ...Debug\Some.wsp" -GacDeployment

我还尝试将上述代码放入脚本中,保存并远程运行脚本。

这是我得到的错误。我相信这是因为我没有管理员权限,我可以这样说是因为当我以管理员身份从 server2 运行部署代码时,正在部署 wsp 文件。那么,我怎样才能远程获得管理员权限。用户具有管理员权限,我需要做的就是以提升的权限运行它(例如右键单击并以管理员身份运行,但以编程方式)

Update-SPSolution:无法访问本地场。在重试之前验证本地场是否已正确配置、当前可用,并且您具有访问数据库的适当权限

编辑

我在powershell的管理员模式下尝试了以下脚本代码:

$password = ConvertTo-SecureString "serverpassword" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential("userName",$password)
Enable-PSRemoting
Enable-WSmanCredSSP -Role Server
winrm set winrm/config/winrs '@{MaxShellsPerUser="25"}'
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="600"}'
Enter-PSSession -ComputerName Server2 -Credential $cred  -Authentication credssp

但是,我不断收到此错误:

Enter-PSSession : Connecting to remote server Server2 failed with the following error message : The WinRM client cannot process the request. CredSSP authentication is currently disabled in the client configuration. Change the client configuration and try the request again. CredSSP authentication must also be enabled in the server configuration. Also, Group Policy must be edited to allow credential delegation to the target computer. Use gpedit.msc and look at the following policy: Computer Configuration -> Administrative Templates -> System -> Credentials Delegation -> Allow Delegating Fresh Credentials. Verify that it is enabled and configured with an SPN appropriate for the target computer. For example, for a target computer name "myserver.domain.com", the SPN can be one of the following: WSMAN/myserver.domain.com or WSMAN/*.domain.com For more information, see the about_Remote_Troubleshooting Help topic

No matter what I try, I get this error. I have tried these techniques:

Can anyone suggest any thing ??

标签: powershellwsp

解决方案


In order to run SharePoint commands remotely please follow the steps outlined in: Remote PowerShell to Manage SharePoint on-premises

Essentially, after enabling remoting, you have to enable CredSSP access in order for your credentials to be sent to the remote and local computer in order for you to run elevated commands.

On the server:

Enable-PSRemoting
Enable-WSmanCredSSP -Role Server
winrm set winrm/config/winrs '@{MaxShellsPerUser="25"}'
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="600"}'

And on the client:

Enable-PSRemoting
Enable-WSmanCredSSP -Role Client -DelegateComputer "server2.contoso.com"

Then on the client you can enter the session:

Enter-PSSession -ComputerName server2 -Credential $cred  -Authentication Credssp

推荐阅读