简体   繁体   English

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

[英]How to execute powershell script from server1 for deploying wsp in server2

I am trying to remotely deploy wsp file present in server2 by running a powershell script in server1. 我试图通过在server1中运行powershell脚本来远程部署server2中存在的wsp文件。

I am able to successfully log in to the server2 through server1 using the below command: 我可以使用以下命令通过server1成功登录到server2:

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

but I am not able to deploy the wsp file. 但我无法部署wsp文件。 This is the code that I tried: 这是我尝试的代码:

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

I have also tried to put the above code in a script, save it and run the script remotely. 我还尝试将以上代码放入脚本中,保存并远程运行脚本。

This is the error that I am getting. 这是我得到的错误。 I believe it is because I don't have admin privileges, I can say this because when I run the deployment code from server2 as admin, the wsp file is getting deployed. 我相信这是因为我没有管理员权限,所以可以这样说是因为当我以admin身份从server2运行部署代码时,正在部署wsp文件。 So, how can I get admin privileges remotely. 因此,我该如何远程获得管理员权限。 The user has the admin privileges, all I need to do is run it with elevated privileges(like right-click and run as admin, but programatically) 该用户具有管理员特权,我需要做的就是以提升的特权运行它(例如右键单击并以管理员身份运行,但以编程方式运行)

Update-SPSolution : Cannot access the local farm. Update-SPSolution:无法访问本地服务器场。 Verify that the local farm is properly configured, currently available, and that you have the appropriate permissions to access the database before trying again 在重试之前,请验证本地服务器场已正确配置,当前可用,并且您具有访问数据库的适当权限。

EDIT 编辑

I have tried the below script code in admin mode in powershell: 我已经在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

However, I keep getting this error: 但是,我不断收到此错误:

Enter-PSSession : Connecting to remote server Server2 failed with the following error message : The WinRM client cannot process the request. Enter-PSSession:连接到远程服务器Server2失败,并显示以下错误消息:WinRM客户端无法处理该请求。 CredSSP authentication is currently disabled in the client configuration. 当前在客户端配置中禁用CredSSP身份验证。 Change the client configuration and try the request again. 更改客户端配置,然后重试该请求。 CredSSP authentication must also be enabled in the server configuration. 还必须在服务器配置中启用CredSSP身份验证。 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. 使用gpedit.msc并查看以下策略:计算机配置->管理模板->系统->凭据委派->允许委派新凭据。 Verify that it is enabled and configured with an SPN appropriate for the target computer. 验证它是否已启用并配置了适用于目标计算机的SPN。 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 例如,对于目标计算机名称“ myserver.domain.com”,SPN可以是以下之一:WSMAN / myserver.domain.com或WSMAN / *。domain.com有关更多信息,请参见about_Remote_Troubleshooting帮助主题

No matter what I try, I get this error. 无论我尝试什么,都会收到此错误。 I have tried these techniques: 我已经尝试过以下技术:

  • Allowed Delegating fresh credentials as well as NTLM fresh credentials in GPEdit. 允许在GPEdit中委派新鲜凭证和NTLM新鲜凭证。
  • I have tried the script present in This link 我已经尝试过链接中的脚本
  • I have added user privileges in compmgmt.msc at Remote Desktop Users WinRMRemoteWMIUsers__ WSS_ADMIN_WPG Remote Management Users 我在远程桌面用户WinRMRemoteWMIUsers__ WSS_ADMIN_WPG远程管理用户的compmgmt.msc中添加了用户权限

Can anyone suggest any thing ?? 谁能建议任何事情?

In order to run SharePoint commands remotely please follow the steps outlined in: Remote PowerShell to Manage SharePoint on-premises 为了远程运行SharePoint命令,请按照以下步骤中概述的步骤进行操作: 在本地管理SharePoint的远程PowerShell

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. 本质上,在启用远程功能后,必须启用CredSSP访问,才能将凭据发送到远程和本地计算机,以便运行提升的命令。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM