【发布时间】:2020-09-07 07:48:55
【问题描述】:
我正在寻找一种清理 SharePoint 以释放一些空间的方法,但偶然发现了一些 PowerShell 脚本来删除 SharePoint Online 中文件的某些版本。 假设您的租户设置了一个文件的 500 个版本,您想要删除旧文件的版本控制,您只是不想删除但也不需要它的 500 个版本。
话虽如此,我正在努力解决如何连接 SharePoint Online、选择特定网站、特定文件,然后删除所有版本。
我在互联网上找到了这个脚本,并且正在研究它,但似乎我应该有一些我不满足的先决条件才能使用这个脚本。
例如,我不理解 Add-Type -Path 部分,据我了解,此脚本适用于 SharePoint 服务器而不是 SharePoint Online。
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com/sites/sales/"
$FileURL="/Sites/Sales/ProjectDocuments/ProjectMetrics.xlsx"
#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred
#Get the File
$File = $Ctx.Web.GetFileByServerRelativeUrl($FileURL)
#Get all versions of the file
$Versions = $File.Versions
$Ctx.Load($Versions)
$Ctx.ExecuteQuery()
Write-host -f Yellow "Total Number of Versions Found :" $Versions.count
#Delete all versions of the file
$Versions.DeleteAll()
$Ctx.ExecuteQuery()
Write-host -f Green "All versions Deleted for given File!"
}
Catch {
write-host -f Red "Error deleting versions!" $_.Exception.Message
}
尤其是在使用 Get-SPWeb cmdlet 时,我会收到以下错误消息:
Get-SPWeb : The term 'Get-SPWeb' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-SPWeb
+ ~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-SPWeb:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
任何帮助和澄清将不胜感激,在此先感谢您!
【问题讨论】:
标签: powershell sharepoint versioning