如何在不安装Sharepoint的情况下将Sharepoint加载项与PowerShell一起使用?

时间:2018-11-20 20:14:57

标签: powershell sharepoint backup remote-access

我正在编写一个Powershell脚本,以将文件从sharepoint复制到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。

任何想法如何使用共享点加载项?谢谢!

1 个答案:

答案 0 :(得分:0)

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

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

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

相关问题