You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows11中获取已登录OneDrive/SharePoint账户邮箱的脚本方案求助

方案1:PowerShell 获取已登录OneDrive账户邮箱列表

方法1:通过OneDrive COM对象直接获取

OneDrive提供COM接口可直接读取已登录账户信息,执行以下脚本:

# 创建OneDrive应用对象
$onedriveApp = New-Object -ComObject OneDrive.Application
# 获取所有已登录账户
$accounts = $onedriveApp.Accounts
# 遍历输出邮箱
foreach ($account in $accounts) {
    Write-Host "已登录OneDrive账户邮箱: $($account.UserEmail)"
}

若执行时提示COM对象创建失败,需确保OneDrive客户端正在运行,且以当前登录用户身份执行脚本。

方法2:读取注册表获取账户信息

OneDrive账户配置存储在用户注册表中,可直接读取:

# 遍历OneDrive账户注册表项
$accountPaths = Get-ChildItem "HKCU:\Software\Microsoft\OneDrive\Accounts"
foreach ($path in $accountPaths) {
    $email = Get-ItemPropertyValue -Path $path.PSPath -Name "UserEmail" -ErrorAction SilentlyContinue
    if ($email) {
        Write-Host "已登录OneDrive账户邮箱: $email"
    }
}

方案2:PowerShell 获取SharePoint映射/同步驱动器

方法1:获取传统映射的SharePoint网络驱动器

若SharePoint是通过「映射到网络驱动器」功能创建的,用以下脚本:

# 获取所有映射的网络驱动器,筛选SharePoint相关项
Get-CimInstance Win32_MappedLogicalDisk | Where-Object { $_.ProviderName -match "sharepoint" } | ForEach-Object {
    Write-Host "SharePoint映射驱动器: $($_.DeviceID),路径: $($_.ProviderName)"
}

方法2:获取OneDrive同步的SharePoint站点(显示在「此电脑」中)

多数SharePoint站点通过OneDrive客户端同步到本地并显示在「此电脑」,用以下脚本读取:

$onedriveApp = New-Object -ComObject OneDrive.Application
$syncLibraries = $onedriveApp.SyncLibraries
foreach ($lib in $syncLibraries) {
    # 筛选SharePoint类型的同步库
    if ($lib.LibraryType -eq "SharePoint") {
        Write-Host "SharePoint同步站点: $($lib.Name),本地路径: $($lib.Path)"
    }
}

无返回值问题排查

  1. 确认OneDrive客户端处于运行状态(右键任务栏图标检查)
  2. 以当前登录用户身份运行PowerShell(不要用管理员权限,可能导致COM对象访问失败)
  3. 更新OneDrive客户端到最新版本:旧版本可能不支持部分接口

内容的提问来源于stack exchange,提问作者Dara O h

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 18:15:37