如何从Server1执行Powershell脚本以在Server2中部署WSP

时间:2019-06-07 15:35:16

标签: powershell 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

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

这是我得到的错误。我相信这是因为我没有管理员权限,所以可以这样说是因为当我以admin身份从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:连接到远程服务器Server2失败   出现以下错误消息:WinRM客户端无法处理   请求。目前,CredSSP身份验证已在   客户端配置。更改客户端配置,然后尝试   再次请求。还必须在CredSSP身份验证中启用   服务器配置。另外,必须编辑组策略以允许   将凭据委派给目标计算机。使用gpedit.msc并查看   在以下策略中:计算机配置->管理   模板->系统->凭证委派->允许委派   新证书。验证是否已启用并配置了   适用于目标计算机的SPN。例如,对于目标   计算机名称为“ myserver.domain.com”,则SPN可以是以下之一   以下:WSMAN / myserver.domain.com或WSMAN / *。domain.com有关更多信息   信息,请参阅about_Remote_Troubleshooting帮助主题

无论我尝试什么,都会遇到此错误。我已经尝试过这些技术:

  • 允许在GPEdit中委派新鲜凭证和NTLM新鲜凭证。
  • 我已经尝试了This链接中的脚本
  • 我在以下位置的compmgmt.msc中添加了用户权限 远程桌面用户 WinRMRemoteWMIUsers__ WSS_ADMIN_WPG 远程管理用户

谁能建议任何事情?

1 个答案:

答案 0 :(得分:0)

为了远程运行SharePoint命令,请遵循以下步骤中概述的步骤:Remote PowerShell to Manage SharePoint on-premises

基本上,启用远程功能后,必须启用CredSSP访问,才能将凭据发送到远程和本地计算机,以便运行提升的命令。

在服务器上:

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

在客户端上:

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

然后在客户端上,您可以进入会话:

Enter-PSSession -ComputerName server2 -Credential $cred  -Authentication Credssp
相关问题