导出 Microsoft OneDrive 体验设置
用户的 Microsoft OneDrive 体验存储信息,以帮助用户查找并导航到他们感兴趣的内容。 最终用户可以使用下表中列出的相应产品内功能访问大部分此信息:
体验 | 存储的数据 | 用户访问权限 |
---|---|---|
共享的项目 | 其他人与用户共享的文档列表。 它还显示用户与其他人共享的文档的视图,这是用户对其 OneDrive 帐户中项目设置的权限的视图。 | 从用户的 OneDrive 中选择“共享”。 |
移动推送通知 | 将通知推送到用户的 OneDrive 和 SharePoint 移动应用(如果已配置)。 这包括相关活动,例如与其共享的新文件。 管理员可以在新 SharePoint 管理中心的“设置”页上管理这些设置。 |
|
关注的网站和内容 | 用户可关注网站、文档或人员。 可以使用产品内体验查看已关注的网站。 |
可以在 SharePoint 主页体验中查看和管理关注的网站。 此体验还显示 “最近使用的网站 ”。 从用户的 OneDrive 帐户中选择“设置”齿轮图标,选择“网站设置”,然后选择“新闻源”。 在右侧,他们可以单击“我正在关注”下的适当内容类型。 |
新闻源 | 用户活动列表,包括关注的内容、提及和配置文件更改。 用户可以使用产品内体验访问它。 | 从用户的 OneDrive 帐户中选择“设置”齿轮图标,选择“网站设置”,然后选择“新闻源”。 如前文所述,可将新闻源设置作为用户配置文件体验的一部分进行管理。 |
访问请求 | 针对内容的访问请求列表。 | 从用户的 OneDrive 帐户中选择“设置”齿轮图标,选择“网站设置”,然后选择“访问请求和邀请” |
管理员可以使用本文中的 PnP PowerShell 和 SharePoint Client-Side 对象模型 (CSOM) 命令导出这些列表。 SharePointPnPPowerShellOnline Microsoft PowerShell 模块中包含所有必需的 CSOM 程序集。
这是一个示例脚本,可以根据组织的需求进行调整。 例如,管理员可以使用以下过程提取 其 user1@contoso.com 信息。
为自己分配对用户 OneDrive 帐户的管理员权限。 这可在 Microsoft 365 管理中心中完成。
安装必需的 Microsoft PowerShell 模块:
Install-Module SharePointPnPPowerShellOnline
Install-Module CredentialManager
运行下面的 ExportODBLists PowerShell 脚本(或自定义版本的脚本):
$ODBSite = "https://contoso-my.sharepoint.com/personal/user1_contoso_com"
ExportODBLists.ps1 -siteUrl $ODBSite
该脚本会将上表中所述的功能存储的数据导出到多个 CSV 文件。 管理员可以在向最终用户提供它们之前对其进行审阅或修订。
如果) 找到相应的列表,该脚本 (创建以下 CSV 文件。 CSV 文件的名称对应于列表的标题。
文件 | 说明 |
---|---|
(引用, <id>) .csv,其中 <id> 是字母和数字的序列 | 与用户共享的项列表 |
共享 Links.csv | 用户生成的共享链接列表 |
userActivityFeedHiddenListF4387007-BE61-432F-8BDB-85E6B9679E4B.csv | 相关活动列表 |
notificationSubscriptionHiddenList6D1E55DA-2564-4A22-A5F9-6C4FCAFF53DE.csv | 发送给移动应用的通知列表和这些设备的应用 ID |
Social.csv | 已关注内容列表 |
MicroFeed.csv | 新闻源项目列表 |
访问 Requests.csv | 访问请求列表 |
SharePointHomeCacheList.csv | 缓存了用户导航到 SharePoint 主页的数据。 每次用户导航到 SharePoint 主页时,都会刷新此项。 |
复制以下内容并将其粘贴到文本文件中。 将文件另存为 ExportODBLists.ps1。 该脚本可以使用 参数从目标列表中 exportAllFields
导出所有字段。 可以修改脚本以导出所有列表以及处理其他网站。
备注
如果看到未加载程序集的错误,请仔细检查最新版本的 SharePointPnPPowerShellOnline PowerShell 模块的路径,如Add-Type Path 参数中定义。 计算机上的路径可能不同,或者你可能使用的是不同版本的模块, (模块版本是路径) 的一部分。
#ExportODBLists
#Exports OneDrive experience settings, stored in several SharePoint lists
param([string]$siteUrl, [bool]$exportAllFields=$false, [bool]$useStoredCreds=$true, [string]$exportFolder)
Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline\2.26.1805.0\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline\2.26.1805.0\Microsoft.SharePoint.Client.Runtime.dll"
if (!$siteUrl)
{
Write-Host "Please specify a OneDrive site using -siteUrl."
return
}
if ($useStoredCreds)
{
Write-Host "Retrieving stored Windows credentials for $siteUrl."
$cred = Get-StoredCredential -Target $siteUrl
if (!$cred)
{
Write-Host "Didn't find stored credential for $siteUrl. Please provide credentials to connect."
$cred = Get-Credential
}
}
else
{
$cred = Get-Credential
}
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($cred.UserName,$cred.Password)
$webURL = $siteUrl
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webURL)
$ctx.Credentials = $credentials
#root folders of lists to export
$SWMRoot = "Reference " #starts with this string
$notificationsRoot = "notificationSubscriptionHiddenList6D1E55DA25644A22"
$activityFeedRoot = "userActivityFeedHiddenListF4387007BE61432F8BDB85E6"
$accessRequestsRoot = "Access Requests"
$microfeedRoot = "PublishedFeed"
$SPHomeCacheRoot = "SharePointHomeCacheList"
$sharingLinksRoot = "Sharing Links"
$socialRoot = "Social"
#list fields to eexport
$SWMFields = @("ID","Created","Modified","Title","RemoteItemPath","OwnerDisplayName","OwnerSipAddress","RemoteItemFileSystemObjectType",
"RemoteItemCreatorDisplayName","RemoteItemCreatorSipAddress","RemoteItemCreatedDateTime",
"RemoteItemModifierDisplayName","RemoteItemModifierSipAddress","RemoteItemModifiedDateTime",
"SWMSharedByDisplayName","SWMSharedBySipAddress","SWMSharedByDateTime",
"RemoteItemLastAccessedDateTime","RemoteItemServerRedirectedUrl","RemoteItemServerRedirectedEmbedUrl")
$accessRequestsFields = @("ID","Created","Modified","Title","RequestId","RequestedObjectTitle","RequestedObjectUrl","PermissionType","PermissionLevelRequested","RequestDate",
"RequestedByDisplayName","RequestedBy","ReqByUser",
"RequestedForDisplayName","RequestedFor","ReqForUser",
"ApprovedBy","AcceptedBy","Status","Expires","WelcomeEmailSubject","WelcomeEmailBody","ExtendedWelcomeEmailBody","Conversation")
$microfeedFields = @("ID","Created","Modified","Title","MicroBlogType","PostAuthor","RootPostOwnerID","RootPostUniqueID","ReplyCoungett","Order","ContentData")
$notificationsFields = @("ID","Created","Modified","Title","SubscriptionId","PoolName","SecondaryPoolName","AppType","NotificationHandle",
"SecondsToExpiry","DestinationType","SubmissionDateTime","ExpirationDateTime","Locale","DeviceId","HostName","NotificationCounter",
"SingleSignOutKey","NotificationScenarios","ComplianceAssetId","AppAuthor","AppEditor")
$SPHomeCacheFields = @("ID","Created","Modified","Author","Editor","Title","Value")
$sharingLinksFields = @("ID","Created","Modified","Title","SharingDocId","ComplianceAssetId","CurrentLink","AvailableLinks")
$socialFields = @("ID","Created","Modified","Author","Editor","Title","Url","Hidden","HasFeed","SocialProperties")
$activityFeedFields = @("ID","Created","Modified","Title","ActivityId","ItemId","PushNotificationsSent","EmailNotificationSent","IsActorActivity","IsRead","Order",
"ItemChildCount","FolderChildCount","ActivityEventType","ActivityEvent")
#get lists in the web
try{
$lists = $ctx.web.Lists
$ctx.load($lists)
$ctx.executeQuery()
}
catch{
write-host "$($_.Exception.Message)" -foregroundcolor red
}
#identify the lists to export
$listsToExport = @()
foreach($list in $lists)
{
$ctx.load($list)
$ctx.load($list.RootFolder)
$ctx.executeQuery()
$listTitle = [string]$list.Title
$listRoot = $list.RootFolder.Name
Write-host ("Processing List: " + $list.Title + " with " + $list.ItemCount + " items").ToUpper() -ForegroundColor Yellow
Write-host (">> List Root Folder: " + $listRoot) -ForegroundColor Yellow
if ($listRoot.StartsWith($SWMRoot,"CurrentCultureIgnoreCase") -and $list.ItemCount -ge 1)
{
Write-Host ">> Found: Shared With Me List" -ForegroundColor Green
$listDetails = @{listType = "Shared With Me List"; listTitle = $listTitle; listRoot = $listRoot; listFields = $SWMFields}
$listsToExport += $listDetails
}
elseif ($listRoot -eq $notificationsRoot)
{
Write-Host ">> Found: Notifications List" -ForegroundColor Green
$listDetails = @{listType = "Notifications List"; listTitle = $listTitle; listRoot = $listRoot; listFields = $notificationsFields}
$listsToExport += $listDetails
}
elseif ($listRoot -eq $activityFeedRoot)
{
Write-Host ">> Found: User Activity Feed List" -ForegroundColor Green
$listDetails = @{listType = "User Activity Feed List"; listTitle = $listTitle; listRoot = $listRoot; listFields = $activityFeedFields}
$listsToExport += $listDetails
}
elseif ($listRoot -eq $accessRequestsRoot)
{
Write-Host ">> Found: Access Requests List" -ForegroundColor Green
$listDetails = @{listType = "Access Requests List"; listTitle = $listTitle; listRoot = $listRoot; listFields = $accessRequestsFields}
$listsToExport += $listDetails
}
elseif ($listRoot -eq $microfeedRoot)
{
Write-Host ">> Found: MicroFeed List" -ForegroundColor Green
$listDetails = @{listType = "Microfeed List"; listTitle = $listTitle; listRoot = $listRoot; listFields = $microfeedFields}
$listsToExport += $listDetails
}
elseif ($listRoot -eq $SPHomeCacheRoot)
{
Write-Host ">> Found: SharePoint Home Cache List" -ForegroundColor Green
$listDetails = @{listType = "SharePoint Home Cache List"; listTitle = $listTitle; listRoot = $listRoot; listFields = $SPHomeCacheFields}
$listsToExport += $listDetails
}
elseif ($listRoot -eq $sharingLinksRoot)
{
Write-Host ">> Found: Sharing Links List" -ForegroundColor Green
$listDetails = @{listType = "Sharing Links List"; listTitle = $listTitle; listRoot = $listRoot; listFields = $sharingLinksFields}
$listsToExport += $listDetails
}
elseif ($listRoot -eq $socialRoot)
{
Write-Host ">> Found: Social List" -ForegroundColor Green
$listDetails = @{listType = "Social List"; listTitle = $listTitle; listRoot = $listRoot; listFields = $socialFields}
$listsToExport += $listDetails
}
}
#export list function
function exportList
{
Param ([string] $listTitle, [string[]]$listFields, [string]$exportFile)
Write-Host ("Exporting List: " + $listTitle).ToUpper() -ForegroundColor Green
Write-Host (">> File location: $exportFile") -ForegroundColor Green
#Get the list items
$list = $lists.GetByTitle($listTitle)
$listItems = $list.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
$fieldColl = $list.Fields
$ctx.load($listItems)
$ctx.load($fieldColl)
$ctx.executeQuery()
if ($listFields) #if you're passing a specific set of fields, in a specific order, process those
{
#Array to Hold List Items
$listItemCollection = @()
#Fetch each list item value to export to excel
foreach($item in $listItems)
{
$exportItem = New-Object PSObject
Foreach ($field in $listFields)
{
if($NULL -ne $item[$field])
{
#Expand the value of Person or Lookup fields
$fieldType = $item[$field].GetType().name
if (($fieldType -eq "FieldLookupValue") -or ($fieldType -eq "FieldUserValue"))
{
$fieldValue = $item[$field].LookupValue
}
elseif ($fieldType -eq "FieldUrlValue")
{
$fieldValue = $item[$field].Url
}
else
{
$fieldValue = $item[$field]
}
}
$exportItem | Add-Member -MemberType NoteProperty -name $field -value $fieldValue
}
#Add the object with above properties to the Array
$listItemCollection += $exportItem
}
#Export the result Array to CSV file
$listItemCollection | Export-CSV $exportFile -NoTypeInformation
}
else #export all fields for the list
{
#Array to Hold List Items
$listItemCollection = @()
#Fetch each list item value to export to excel
foreach($item in $listItems)
{
$exportItem = New-Object PSObject
Foreach($field in $fieldColl)
{
if($NULL -ne $item[$field.InternalName])
{
#Expand the value of Person or Lookup fields
$fieldType = $item[$field.InternalName].GetType().name
if (($fieldType -eq "FieldLookupValue") -or ($fieldType -eq "FieldUserValue"))
{
$fieldValue = $item[$field.InternalName].LookupValue
}
elseif ($fieldType -eq "FieldUrlValue")
{
$fieldValue = $item[$field].Url
}
else
{
$fieldValue = $item[$field.InternalName]
}
}
$exportItem | Add-Member -MemberType NoteProperty -name $field.InternalName -value $fieldValue
}
#Add the object with above properties to the Array
$listItemCollection += $exportItem
}
#Export the result Array to CSV file
$listItemCollection | Export-CSV $exportFile -NoTypeInformation
}
}
#export the lists
foreach ($list in $listsToExport)
{
#if we have a valid folder for export, use it, otherwise export to the current directory
if ($exportFolder -and (Test-Path $exportFolder -PathType Container))
{
$filepath = Join-Path -Path $exportFolder -ChildPath ($list["listTitle"] + ".csv")
}
else
{
$filepath = ($list["listTitle"] + ".csv")
}
#export the lists
if ($exportAllFields)
{
exportList -listTitle $list["listTitle"] -exportFile $filepath
}
else
{
exportList -listTitle $list["listTitle"] -listFields $list["listFields"] -exportFile $filepath
}
}