如何从服务器 1 执行 Powershell 脚本以在服务器 2 中部署 wsp



我正在尝试通过在服务器 1 中运行 powershell 脚本来远程部署服务器 2 中存在的 wsp 文件。

我能够使用以下命令通过服务器 1 成功登录到服务器 2:

$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 ...DebugSome.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

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

输入 PSSession : 连接到远程服务器 Server2 失败 出现以下错误消息:WinRM 客户端无法处理 请求。CredSSP 身份验证当前在 客户端配置。更改客户端配置并尝试 再次请求。还必须在 服务器配置。此外,必须编辑组策略以允许 对目标计算机的凭据委派。使用 gpedit.msc 并查看 遵循以下策略:计算机配置 ->管理 模板 -> 系统 ->凭据委派 -> 允许委派 新鲜凭据。 验证它是否已启用并配置了 适用于目标计算机的 SPN。例如,对于目标 计算机名称"myserver.domain.com",SPN 可以是 以下: WSMAN/myserver.domain.com 或 WSMAN/*.domain.com 信息,请参阅about_Remote_Troubleshooting帮助主题

无论我尝试什么,我都会收到此错误。我尝试了这些技术:

  • 允许在 GPEdit 中委派新凭据以及 NTLM 新凭据。
  • 我已经尝试了此链接中存在的脚本
  • 我在 compmgmt.msc 中添加了用户权限 远程桌面用户 WinRMRemoteWMIUsers__ WSS_ADMIN_WPG 远程管理用户

任何人都可以提出任何建议吗?

若要远程运行 SharePoint 命令,请按照以下步骤操作:用于本地管理 SharePoint 的远程 PowerShell

实质上,启用远程处理后,必须启用 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

最新更新