[玩转系统] 使用 PowerShell 查找所有 OneDrive for Business 网站
作者:精品下载站 日期:2024-12-14 21:08:40 浏览:16 分类:玩电脑
使用 PowerShell 查找所有 OneDrive for Business 网站
要求:从 SharePoint Online 获取所有 OneDrive 网站集的列表。
我被要求获取所有 OneDrive 站点的列表,以了解 Office 365 租户中 OneDrive for Business 的使用情况。查找所有 OneDrive 网站集有点棘手,以下是我使用 Get-SPOSite cmdlet 实现此目的的方法:
如何列出所有 OneDrive for Business URL?
OneDrive for Business 是一种基于云的文件存储服务,是 Microsoft 365 工具套件的一部分。作为管理员,您可能需要获取组织中所有 OneDrive 网站的列表,以进行审核或管理。在本文中,我们将概述使用 Microsoft 365 管理中心和 PowerShell 获取 Microsoft 365 中的所有 OneDrive 网站的步骤。
若要通过 Microsoft 365 管理中心获取组织中所有 OneDrive for Business 网站的列表,请执行以下操作:
- 登录 Microsoft 365 管理中心 https://admin.microsoft.com
- 单击左侧导航中的“报告”>> 单击“使用情况”。
- 在 OneDrive 文件下,单击“查看更多”
向下滚动一点可查看提供所有 OneDrive 站点列表的报告。您还可以将报告数据导出为 CSV 格式以供进一步分析。
使用 SharePoint Online Management Shell 查找所有 OneDrive 网站:
OneDrive for Business 提供集中存储来保存和共享文件。 OneDrive中存储的文件可以在任何设备上下载并同步到云端,以确保数据一致性。让我们使用 PowerShell 查找 SharePoint Online 中的所有 OneDrive 网站集。此 PowerShell 脚本通过筛选网站模板属性来获取 SharePoint Online 中的所有 OneDrive 网站集。
$AdminSiteURL="https://crescent-admin.sharepoint.com"
#Get Credentials to connect to SharePoint Admin Center
$Cred = Get-Credential
#Connect to SharePoint Online Admin Center
Connect-SPOService -Url $AdminSiteURL -credential $Cred
#Get all Personal Site collections and export to a Text file
Get-SPOSite -Template "SPSPERS" -limit ALL -includepersonalsite $True | Select URL, Owner | Format-table -autosize | Out-string -width 8096 | Out-file C:\temp\OneDriveSites.txt
只需将 $AdminSiteURL 更改为您的域,提供 SharePoint Online 管理员的凭据,然后运行脚本即可。此脚本在“C:\Temp\OneDriveSites.txt”文件上生成输出。
使用 PowerShell 列出所有 OneDrive for Business 网站
您还可以使用 -Filter 您还可以在 Get-SPOSite cmdlet 中使用 -Filter 开关,如下所示:
Get-SPOSite -IncludePersonalSite $true -Limit all -Filter "Url -like '-my.sharepoint.com/personal/'"
使用 PnP PowerShell 获取所有 OneDrive 站点
我们可以使用 PnP PowerShell 检索所有 OneDrive 网站集的列表,如下所示:
#Config Variables
$TenantSiteURL = "https://crescent-admin.sharepoint.com/"
#Connect to PnP Online
Connect-PnPOnline -Url $TenantSiteURL -Interactive
#Get All OneDrive Sites
Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'"
让我们将所有 OneDrive 站点导出到 CSV 文件:
#Parameter
$Tenant = "CrescentIntranet"
$CSVPath = "C:\Temp\OneDriveSites.csv"
#Connect to PnP Online
Connect-PnPOnline -Url "https://$tenant-admin.sharepoint.com" -Interactive
#Get OneDrive Site Details and export to CSV
Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like 'https://$tenant-my.sharepoint.com/personal/'" |
Select Title, URL, Owner, LastContentModifiedDate, StorageUsage |
Export-Csv -Path $CSVPath -NoTypeInformation
使用 PowerShell 获取所有 OneDrive 站点 - CSOM:
作为替代方法,您可以使用 PowerShell CSOM 获取所有 OneDrive 网站集。此脚本使用 UserProfileService 获取所有 SharePoint Online 用户并检查用户是否有个人网站。以下是使用 PowerShell 列出所有 OneDrive for Business 网站的脚本:
#Add references to SharePoint client assemblies
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles")
# Specify sharepoint online admin url
$AdminSiteURL = "https://crescent-admin.sharepoint.com"
$MySiteURL="https://crescent-my.sharepoint.com"
#Specify the location where the list of OneDrive sites should be saved
$LogFile = "C:\Temp\OneDriveSites.txt"
#Setup Credentials to connect
$AdminCred= Get-Credential
$AdminCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($AdminCred.Username, $AdminCred.Password)
#Set User Profile Service path using SPO admin URL
$ProxyAddr = "$AdminSiteURL/_vti_bin/UserProfileService.asmx?wsdl"
# Create a new webservice proxy to access UserProfileService
$UserProfileService= New-WebServiceProxy -Uri $ProxyAddr -UseDefaultCredential False
$UserProfileService.Credentials = $AdminCredentials
#Set authentication cookies
$StrAuthCookie = $AdminCredentials.GetAuthenticationCookie($AdminSiteURL)
$URI = New-Object System.Uri($AdminSiteURL)
$Container = New-Object System.Net.CookieContainer
$Container.SetCookies($URI, $StrAuthCookie)
$UserProfileService.CookieContainer = $Container
# Sets the first User profile, at index -1
$UserProfileResult = $UserProfileService.GetUserProfileByIndex(-1)
$NumProfiles = $UserProfileService.GetUserProfileCount()
$i = 1
# As long as the next User profile is NOT the one we started with (at -1)...
While ($UserProfileResult.NextValue -ne -1)
{
Write-Host "Checking profile $i of $NumProfiles" -foreground Yellow
# Look for the Personal Space object in the User Profile and retrieve it
$Prop = $UserProfileResult.UserProfile | Where-Object { $_.Name -eq "PersonalSpace" }
$URL= $Prop.Values[0].Value
# If "PersonalSpace" (which we've copied to $Url) exists, log it to our file...
if ($URL)
{
$SiteUrl = $MySiteURL+$URL
# Write OneDrive site url to the console
Write-Host $SiteUrl -foreground Green
$SiteUrl | Out-File $LogFile -Append -Force
}
# And now we check the next profile the same way...
$UserProfileResult = $UserProfileService.GetUserProfileByIndex($UserProfileResult.NextValue)
$i++
}
结论:
通过执行这些简单的步骤,您可以使用 Microsoft 365 管理中心或 PowerShell 快速获取组织中所有 OneDrive 网站的列表。这可用于多种目的,例如审计、报告或管理。 Microsoft 365 管理中心提供了一个用户友好的界面来管理 OneDrive 环境,而 PowerShell 提供了更强大的自动化功能。无论您选择哪种方法,该过程都很简单且易于遵循。
猜你还喜欢
- 03-30 [玩转系统] 如何用批处理实现关机,注销,重启和锁定计算机
- 02-14 [系统故障] Win10下报错:该文件没有与之关联的应用来执行该操作
- 01-07 [系统问题] Win10--解决锁屏后会断网的问题
- 01-02 [系统技巧] Windows系统如何关闭防火墙保姆式教程,超详细
- 12-15 [玩转系统] 如何在 Windows 10 和 11 上允许多个 RDP 会话
- 12-15 [玩转系统] 查找 Exchange/Microsoft 365 中不活动(未使用)的通讯组列表
- 12-15 [玩转系统] 如何在 Windows 上安装远程服务器管理工具 (RSAT)
- 12-15 [玩转系统] 如何在 Windows 上重置组策略设置
- 12-15 [玩转系统] 如何获取计算机上的本地管理员列表?
- 12-15 [玩转系统] 在 Visual Studio Code 中连接到 MS SQL Server 数据库
- 12-15 [玩转系统] 如何降级 Windows Server 版本或许可证
- 12-15 [玩转系统] 如何允许非管理员用户在 Windows 中启动/停止服务
取消回复欢迎 你 发表评论:
- 精品推荐!
-
- 最新文章
- 热门文章
- 热评文章
[影视] 黑道中人 Alto Knights(2025)剧情 犯罪 历史 电影
[古装剧] [七侠五义][全75集][WEB-MP4/76G][国语无字][1080P][焦恩俊经典]
[实用软件] 虚拟手机号 电话 验证码 注册
[电视剧] 安眠书店/你 第五季 You Season 5 (2025) 【全10集】
[电视剧] 棋士(2025) 4K 1080P【全22集】悬疑 犯罪 王宝强 陈明昊
[软件合集] 25年6月5日 精选软件22个
[软件合集] 25年6月4日 精选软件36个
[短剧] 2025年06月04日 精选+付费短剧推荐33部
[短剧] 2025年06月03日 精选+付费短剧推荐25部
[软件合集] 25年6月3日 精选软件44个
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电视剧] 欢乐颂.5部全 (2016-2024)
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[影视] 【稀有资源】香港老片 艺坛照妖镜之96应召名册 (1996)
[剧集] 神经风云(2023)(完结).4K
[剧集] [BT] [TVB] [黑夜彩虹(2003)] [全21集] [粤语中字] [TV-RMVB]
[实用软件] 虚拟手机号 电话 验证码 注册
[资源] B站充电视频合集,包含多位重量级up主,全是大佬真金白银买来的~【99GB】
[影视] 内地绝版高清录像带 [mpg]
[书籍] 古今奇书禁书三教九流资料大合集 猎奇必备珍藏资源PDF版 1.14G
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电影] 美国队长4 4K原盘REMUX 杜比视界 内封简繁英双语字幕 49G
[电影] 死神来了(1-6)大合集!
[软件合集] 25年05月13日 精选软件16个
[精品软件] 25年05月15日 精选软件18个
[绝版资源] 南与北 第1-2季 合集 North and South (1985) /美国/豆瓣: 8.8[1080P][中文字幕]
[软件] 25年05月14日 精选软件57个
[短剧] 2025年05月14日 精选+付费短剧推荐39部
[短剧] 2025年05月15日 精选+付费短剧推荐36部
- 最新评论
-
- 热门tag