powershell 无法远程执行sharepoint脚本

qhhrdooz  于 2023-05-17  发布在  Shell
关注(0)|答案(1)|浏览(187)

看看有没有人能帮我。我对这个可以远程执行的简单脚本很着迷。
在上下文中,我试图从一台没有安装Sharepoint的服务器上执行Sharepoint脚本。这是我尝试运行的脚本:

$SPUser = "Sharepoint_user"
$SPPassword = "SharePoint_Password"
$Password = convertto-securestring -String $SPPassword -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentList $SPUser, $Password
$SPServer = "Sharepointserver"

 Invoke-Command -ComputerName $SPServer -Credential $cred -ErrorVariable InvokeErrorMessage -Scriptblock {

         Add-PSSnapin Microsoft.SharePoint.PowerShell -ea continue
         Get-SPWeb -Identity 'https://sharepointsite.com'

    }#end Invoke-Command

这是我得到的错误:

Cannot access the local farm. Verify that the local farm is properly configured, currently available, and that you have the appropriate 
permissions to access the database before trying again.
    + CategoryInfo          : InvalidData: (Microsoft.Share....SPCmdletGetWeb:SPCmdletGetWeb) [Get-SPWeb], SPCmdletException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetWeb
If I run the same script in the Sharepoint server (off course without the invoke-command), the script works perfectly.

我正在使用的用户帐户已经是场和网站集组的成员,并且在Sharepoint服务器中具有管理员权限。此外,还具有在SQL Server(SharePoint_Shell_Access)中执行sharepoint脚本的权限,并设置为“sysadmin”和“dbcreator”。
我也试着用NEW-PSSSESSION执行,但它也不起作用。我得到了同样的错误。
有什么想法,我错过了配置?
提前感谢您的帮助!
我已经尝试使用调用命令和新的PsSession执行查看了用户帐户的权限,如果Sharepoint场配置查看了SQL数据库中的角色和权限测试了远程执行helloworld powershell脚本(没有任何Sharepoint cmdlet)并正常工作

相关问题