【问题标题】:How use Sharepoint add-ins with PowerShell without installing Sharepoint?如何在不安装 Sharepoint 的情况下将 Sharepoint 加载项与 PowerShell 一起使用?
【发布时间】:2019-10-28 22:50:45
【问题描述】:

我正在编写一个 powershell 脚本来将文件从共享点复制到 Windows 计算机位置。我不想在 Windows 计算机上安装 sharepoint 来运行这个 powershell 脚本。我们只需要在运行我们的共享点的服务器上使用它。我的脚本的目的是将文件从共享点复制到 Windows 计算机作为备份。

我正在关注this example。但是,当我运行它(使用 add-psSnapin)时,我得到:

"Add-PSSnapin:Windows PowerShell 管理单元 此计算机上未安装“Microsoft.SharePoint.PowerShell”。”

我正在查看this article,它似乎采用了我在脚本中添加的 Enable-PSRemoting。

这是我到目前为止的脚本,就像我上面给出的链接:

#run 64 bit powershell version as administrator (doing this): https://stackoverflow.com/questions/19055924/how-to-launch-64-bit-powershell-from-32-bit-cmd-exe 

Set-ExecutionPolicy RemoteSigned #permission to run scripts
Enable-PSRemoting
Get-PSSnapin -Registered | Add-PSSnapin -Passthru
#Add-PSSnapin Microsoft.SharePoint.PowerShell

$tempSource = "http://sharepoint.college.edu/sites/Disaster%20Plan/Forms/AllItems.aspx"
$ToLocation = "C:\Users\mcl8\Documents\2018\powershellFiles\toLoc\"

$web = Get-SPWeb -Identity "http://sharepoint.college.edu/sites/Disaster%20Plan/Forms/"
$list = $web.GetList("http://sharepoint.college.edu/sites/Disaster%20Plan/Forms/AllItems.aspx")


function ProcessFolder{
   param($SourceUrl)
   $folder = $web.GetFolder($SourceUrl)
   foreach ($file in $folder.Files) {
      #Ensure destination dir
      $destinationFolder = $destination + "/" + $folder.Url
      if (!(Test-Path -path $destinationFolder))
      {
         $dest = New-Item $destinationFolder -type directory
      }
      #Download file
      $binary = $file.OpenBinary()
      $stream = New-Object System.IO.FileStream($destinationFolder + "/" + $file.Name), Create
      $writer = New-Object System.IO.BinaryWriter($stream)
      $writer.Close()
   }

} #ProcessFolder

#################start here##################################

#run this as administrator

#Download root files
ProcessFolder($list.RootFolder.Url)
#Download files in folders
foreach ($folder in $list.Folders) {
   #ProcessFolder($folder.Url)
}

在 Get-SPWeb 上失败如下:

Get-SPWeb : 术语“Get-SPWeb”未被识别为 cmdlet、函数、脚本文件或可运行的程序。检查拼写 的名称,或者如果包含路径,请验证该路径是 正确并重试。

我尝试取消注释 Add-PSSnapin 行,但失败了:

Add-PSSnapin:Windows PowerShell 管理单元 此计算机上未安装“Microsoft.SharePoint.PowerShell”。

但是,就像我说的,我不想在我的计算机上安装 Sharepoint。

任何想法如何使用 sharepoint 加载项?谢谢!

【问题讨论】:

  • 您将需要这些模块。如果您不想运行 SharePoint 安装程序,请查看 PnP-PowerShell

标签: powershell sharepoint backup remote-access


【解决方案1】:

如果您只需要复制文件,则不需要任何特殊的脚本或模块。通常您可以将共享点库视为网络文件夹。将此复制到文件资源管理器中,看看是否可以打开它。

\\sharepoint.college.edu\DavWWWRoot\sites\Disaster%20Plan\

或者您也可以在 Internet Explorer 中打开您的图书馆位置,应该有一个类似“打开为文件夹”之类的按钮。那么你所需要的就是 Copy-Item

【讨论】:

  • 文件资源管理器向我显示了 Forms 目录的内容,但是当我尝试连接到 AllItems.aspx 时,它询问我想用什么打开它。它是文件类型 asp.net 服务器页面。我不确定复制 AllItems.aspx 是否会复制共享点文件内容。当我在 sharepoint 中时,转到该位置会在浏览器中列出大约 10 个文件。
  • 您不需要连接到 Allitems 或任何东西。只需在文件资源管理器中找到您需要的文件夹,上一级,转到文件夹属性,复制位置。然后去powershell,输入cd“thatFolderLocation”,然后ls。之后你看到你的文件了吗?如果有问题,你可以把你在做什么的截图
  • 当我尝试在 powershell 中 cd 那个位置时,它说访问被拒绝。权限被拒绝 UnauthorizedAccessException。一定是 powershell 没有我的登录名,但文件管理器知道我已经登录,所以我可以看到 AllItems 所在的目录
  • 我也试过Forms上面的目录,它也有UnauthorizedAccessException
  • 奇怪,你是作为有访问权限的用户登录的吗?还是你不使用 AD 认证?
猜你喜欢
  • 2012-07-11
  • 1970-01-01
  • 2011-09-20
  • 1970-01-01
  • 2019-10-28
  • 1970-01-01
  • 2017-03-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多