惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
V
V2EX
WordPress大学
WordPress大学
Google DeepMind News
Google DeepMind News
Martin Fowler
Martin Fowler
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
The Cloudflare Blog
T
Tailwind CSS Blog
H
Help Net Security
腾讯CDC
爱范儿
爱范儿
人人都是产品经理
人人都是产品经理
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
Stack Overflow Blog
Stack Overflow Blog
D
DataBreaches.Net
C
Check Point Blog
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

博客园 - 霖雨

用PowerShell命令一次启动多个前后端应用 Visual Studio Code中配置Cline 解决MSSQLLocalDB连接失败的问题 使用App Registration 访问 SharePoint Online (二) 使用App Registration 访问 SharePoint Online (一) SharePoint Online 文档库的还原功能 SharePoint Online 快捷方式功能 SharePoint Online 文档库的收藏功能 使用豆包开发SharePoint Framework项目 Power Automate 还原误删的 Flow PowerShell 获取已删除的 Automate Flow PowerShell 新建 Address Book Policy PowerShell 批量添加用户到组 PowerShell 批量下载 SharePoint Online 文档 PowerShell 清空 SharePoint Online 列表数据 PowerShell 新建 SharePoint Online 列表 PowerShell 启用 SharePoint Online CDN SharePoint Online 定时发布页面 SharePoint Online 页面诊断 Microsoft Whiteboard 的使用 SharePoint Online 网站配置时区 SharePoint Online 集成 Viva Connections SharePoint Online 分区模板 SharePoint Online 嵌入 Power BI 报表
PowerShell 获取 SharePoint Online 站点信息
霖雨 · 2026-02-28 · via 博客园 - 霖雨

  前言

  最近,用户想要查一些站点的信息,当然,如果个别站点那就非常容易了,批量的话你懂的。

  正文

  1.这是PowerShell 命令执行成功的页面,命令附后,如下图:

image

  2.这是获取一个站点的信息,如果你想获取多个,稍微改一下,就好了,如下图:

$siteUrl = "https://linyus.sharepoint.com/sites/Develop"  # 替换为你的SPO站点地址

if (-not (Get-Module -ListAvailable -Name PnP.PowerShell)) {
    Write-Host "正在安装最新版PnP.PowerShell..." -ForegroundColor Cyan
    Set-PSRepository -Name PSGallery -InstallationPolicy Trusted -ErrorAction SilentlyContinue
    Install-Module -Name PnP.PowerShell -Force -AllowClobber -Scope CurrentUser -ErrorAction Stop
}

Import-Module PnP.PowerShell -DisableNameChecking -Force -ErrorAction Stop
Write-Host "✅ PnP.PowerShell模块加载成功`n" -ForegroundColor Green

$isConnected = $false

try {
    Write-Host "🔗 正在连接站点: $siteUrl" -ForegroundColor Cyan
    Connect-PnPOnline -Url $siteUrl -UseWebLogin -ErrorAction Stop
    $isConnected = $true
    Write-Host "✅ 站点连接成功`n" -ForegroundColor Green

    Write-Host "📊 开始获取站点信息...`n" -ForegroundColor Cyan

    $web = Get-PnPWeb -ErrorAction Stop
    $site = Get-PnPSite -ErrorAction Stop

    $allLists = Get-PnPList -ErrorAction Stop
    $documentLibraries = $allLists | Where-Object { $_.BaseTemplate -eq 101 }  # 101=文档库
    $customLists = $allLists | Where-Object { $_.BaseTemplate -eq 100 }      # 100=自定义列表

    Write-Host "========== SharePoint Online 站点核心信息 ==========" -ForegroundColor Green
    [PSCustomObject]@{
        "站点标题"         = $web.Title
        "站点URL"          = $web.Url
        "列表/库总数"      = $allLists.Count
        "文档库数量"       = $documentLibraries.Count
        "自定义列表数量"   = $customLists.Count
    } | Format-List

    Write-Host "`n========== 站点内前5个列表/库(名称+类型) ==========" -ForegroundColor Green
    $allLists | Select-Object Title, BaseTemplate -First 5 | Format-Table -AutoSize

}
catch {
    Write-Host "`n❌ 执行出错: $($_.Exception.Message)" -ForegroundColor Red
    exit 1
}
finally {
    # 修复连接检测逻辑:仅在确认连接成功时断开
    if ($isConnected) {
        try {
            Disconnect-PnPOnline -ErrorAction SilentlyContinue
            Write-Host "`n🔌 已断开SPO站点连接" -ForegroundColor Cyan
        }
        catch {
            Write-Host "`n⚠️ 断开连接时出现小问题,可忽略: $($_.Exception.Message)" -ForegroundColor Yellow
        }
    }
}

  结束语

  在管理SharePoint Online站点的时候,PowerShell是一个非常好用的工具,尤其是批量建表、处理数据等。