简体   繁体   English

通过 Powershell 访问 Sharepoint Online 回收站

[英]Access Sharepoint Online Recycle Bin through Powershell

I need to restore a massive amount of deleted files back into Sharepoint.我需要将大量已删除的文件还原回 Sharepoint。 Sharepoint is a disgusting beast that should be avoided at all costs, of course, but a client is running it and I need to find a resolution for them. Sharepoint 是一个令人作呕的野兽,当然应该不惜一切代价避免,但客户正在运行它,我需要为他们找到解决方案。

Connect-SPOService -Url https://clientdomain-admin.sharepoint.com -Credential $userCredential

So far so good.到目前为止,一切都很好。

$Site = Get-SPOSite
Write-Host $Site

Output: Microsoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSite输出:Microsoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell。 SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.Online.Sharepoint.Powershell.SPOSiteMicrosoft.在线.Sharepoint.Powershell.SPOSite

I am not kidding.我没在闹着玩。 So trying a different way:所以尝试不同的方式:

$SiteUrl = "https://clientdomain.sharepoint.com"
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Site = $Context.Site
$RecycleBinItems = $Site.RecycleBin
Write-Host "Total Number of Items:" $RecycleBinItems.Count

Output: "Total Number of Items: 0输出:“项目总数:0

I am stuck at this point.我被困在这一点上。 Does anyone know how to access the Recycle Bin this way?有谁知道如何以这种方式访问回收站?

Wow, been messing with this for hours and finally got it.哇,弄乱了几个小时,终于明白了。 Full code:完整代码:

$SiteUrl = "https://clientdomain.sharepoint.com"
$AdminUserName = "administrator@clientdomain.com"
$Password = Read-host -assecurestring "Enter Password for $AdminUserName"
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($AdminUserName,$Password)
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Context.Credentials = $Credentials
$Site = $Context.Site
$RecycleBinItems = $Site.RecycleBin
$Context.Load($Site)
$Context.Load($RecycleBinItems)
$Context.ExecuteQuery()
Write-Host "Total Number of Items:" $RecycleBinItems.Count

Output: 14440输出:14440

Bisclavret's answer worked for me. Bisclavret 的回答对我有用。

I needed to export the list so I added an export path before the query and then "$RecycleBinItems | Export-Csv -Path $FilePath NoTypeInformation" at the end as below.我需要导出列表,所以我在查询之前添加了导出路径,然后在末尾添加了“$RecycleBinItems | Export-Csv -Path $FilePath NoTypeInformation”,如下所示。

$FilePath = "C:\Users\Admin\Documents\Restore from recycle bin\restore.csv" 
$Context.ExecuteQuery() 
$RecycleBinItems | Export-Csv -Path $FilePath 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM