通过Powershell访问Sharepoint Online回收站

时间:2018-03-09 04:16:01

标签: powershell sharepoint

我需要将大量已删除的文件还原回Sharepoint。 Sharepoint是一种恶心的野兽,当然应该不惜一切代价避免,但客户正在运行它,我需要为它们找到解决方案。

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

到目前为止一切顺利。

$Site = Get-SPOSite
Write-Host $Site

输出: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

我不是在开玩笑。所以尝试不同的方式:

$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

输出:“项目总数:0

我在这一点上陷入困​​境。有谁知道如何以这种方式访问​​回收站?

2 个答案:

答案 0 :(得分:0)

哇,这几个小时都搞乱了,终于明白了。完整代码:

$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

输出:14440

答案 1 :(得分:0)

Bisclavret 的回答对我有用。

我需要导出列表,所以我在查询之前添加了一个导出路径,然后 “$RecycleBinItems | Export-Csv -Path $FilePath NoTypeInformation” 结尾如下。

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