【发布时间】: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