当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:使用 PowerShell 获取用户的 OneDrive for Business URL

作者:精品下载站 日期:2024-12-14 21:13:50 浏览:14 分类:玩电脑

SharePoint Online:使用 PowerShell 获取用户的 OneDrive for Business URL


要求:PowerShell 获取 SharePoint Online 中的 OneDrive URL。

如何获取用户的 OneDrive URL?

SharePoint On-premises 中的“我的网站”变成了 SharePoint Online 中的 OneDrive for Business。 OneDrive for Business 是一个基于云的文件存储和协作平台,与 Office 365 集成。它提供用于存储和共享文件的集中位置,以及实时协作和通信功能。通常,OneDrive 网站位于以下 URL:https://tenant-my.sharepoint.com/personal/upn(例如,https://crescent-my.sharepoint.com/personal/salaudeen_crescent_com 或 https://crescent-my.sharepoint.com/personal/salaudeen_crescent_onmicrosoft_com)。

要获取 SharePoint Online 用户的 OneDrive 网站,请按照以下步骤操作:

  1. 登录 SharePoint Online 管理中心 https://YourDomain-Admin.SharePoint.com
  2. 单击左侧导航中的“用户配置文件”链接 >> 单击“人员”组下的“管理用户配置文件”链接。

    [玩转系统] SharePoint Online:使用 PowerShell 获取用户的 OneDrive for Business URL

  3. 搜索并选择您想要访问的用户配置文件。在搜索结果中,单击上下文菜单中的菜单项“管理个人网站”。

    [玩转系统] SharePoint Online:使用 PowerShell 获取用户的 OneDrive for Business URL

这将带您进入 OneDrive 网站! (如果 OneDrive 网站已创建。)让我们使用 PowerShell 获取 OneDrive for Business URL。

您还可以从 Office 365 管理中心获取用户的 OneDrive 站点!登录 Office 365 管理中心 https://admin.microsoft.com,搜索并找到用户。在用户设置页面中,单击 OneDrive 选项卡 >> 单击“创建文件链接”,您将看到指向用户 OneDrive 站点的链接!

SharePoint Online:用于获取 OneDrive URL 的 PowerShell

让我们查询用户个人资料以检索个人站点 URL。在运行脚本之前,请记住设置用户名和管理站点 URL 参数。


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll"

#Set Config Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$UserAccount="[email protected]"

Try {
    #Setup Credentials to connect
    $Cred= Get-Credential
 
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminSiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
         
    #Get the User
    $User = $Ctx.web.EnsureUser($UserAccount)
    $Ctx.Load($User)
    $Ctx.ExecuteQuery()
 
    #Get OneDrive Site URL from User Profile
    $PeopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($Ctx)
    $UserProfile = $PeopleManager.GetPropertiesFor($User.LoginName)
    $Ctx.Load($UserProfile)
    $Ctx.ExecuteQuery()

    #Get the User Profile Property
    Write-host $UserProfile.PersonalUrl
 
}
Catch {
    write-host -f Red "Error Getting User Profile Properties!" $_.Exception.Message
}

此脚本检索给定用户的 OneDrive (MySite) URL。例如,https://crescent-my.sharepoint.com/personal/salaudeen_crescent_com/

PnP PowerShell 获取用户的 OneDrive URL:

同样,您可以使用 PnP PowerShell 查询用户配置文件并获取我的站点 URL,如下所示:


#Set Config Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$UserAccount="[email protected]" #UPN

#Connect to the site
Connect-PnPOnline $AdminSiteURL -Interactive

#powershell to get onedrive for business url
Get-PnPUserProfileProperty -Account $UserAccount | Select PersonalUrl

这是获取租户的所有 OneDrive 网站集的另一篇文章:使用 PowerShell 在 SharePoint Online 中查找所有 OneDrive 网站集

经常问的问题:

如何查找 OneDrive for Business 的 URL?

打开 https://www.office.com/,然后使用您的帐户登录 >> 单击应用程序启动器 >> 单击“OneDrive”。这将带您进入 OneDrive for Business 主页。 (网址快捷方式:https://YourDomain-my.sharepoint.com)。
更多信息:如何打开OneDrive for Business网站?

如何列出 OneDrive for Business 网站的所有 URL?

登录 Microsoft 365 管理中心 https://admin.microsoft.com >> 单击左侧导航中的“报告”>> 单击“使用情况”>> 在 OneDrive 文件下,单击“查看更多”。此报告为您提供组织中所有 OneDrive 网站的列表。您也可以将报告数据导出到 CSV 中。
更多信息:列出所有 OneDrive for Business URL

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯