【问题标题】:Get Site Classification via PowerShell通过 PowerShell 获取站点分类
【发布时间】:2021-03-23 14:15:49
【问题描述】:

对于内部审计/验证,我是否需要加载我的租户中的所有站点,其中站点的 classification 设置为“仅限内部”(为我们的租户创建的自定义分类)。

似乎我无法使用标准 PowerShell 模块 Microsoft.Online.SharePoint.PowerShell 检索分类 - Get-SPOSite 返回的对象根本没有提供属性 Classification

我发现的唯一方法是使用PnP.PowerShell,请参阅Microsoft 文档Programmatically read the classification of a site

Connect-PnPOnline "https://[tenant].sharepoint.com/sites/[modernsite]" -Credentials [credentials]

$site = Get-PnPSite
$classificationValue = Get-PnPProperty -ClientObject $site -Property Classification
Write-Host $classificationValue

但是基于 PnP.PowerShell 的方法的问题在于,我需要成为该站点的管理员/所有者才能加载站点对象。如果我不是管理员/所有者,在执行Get-PnPSite 时会出现以下错误:

Get-PnPSite : The remote server returned an error: (401) Unauthorized.

现在的问题是,我是否可以在不成为网站集管理员的情况下检索租户中所有网站的分类?

【问题讨论】:

    标签: powershell sharepoint-online


    【解决方案1】:

    网站集管理员是检索分类属性所必需的。

    作为租户管理员,您可以通过 powershell 将自己添加为网站集管理员。检索信息后,只需从站点集合管理员中删除 Admin 帐户即可。

    如下:

    $site="https://[tenant].sharepoint.com/sites/[modernsite]"
    $admin="admin@tenant.com"
    #Add Admin account as an additional site collection adminstrator
    Set-PnPTenantSite  $site -Owners $admin
    
    Connect-PnPOnline $site -Credentials [credentials]
    
    $site = Get-PnPSite
    $classificationValue = Get-PnPProperty -ClientObject $site -Property Classification
    Write-Host $classificationValue
    
    #Remove Admin account from site colletion administrators
    Remove-PnPSiteCollectionAdmin -Owners $admin
    

    【讨论】:

    • 我被配置为“全局管理员”,但只有当我是给定站点的“站点管理员”时才能获得分类。
    • 全局管理员无法自动访问所有网站集。正如我所说,您可以将自己添加为网站管理员。
    【解决方案2】:

    您确实需要 SharePoint 管理员角色才能使其工作...没有办法解决它。

    【讨论】:

    • 我被配置为“全局管理员”,但只有当我是给定站点的“站点管理员”时才能获得分类。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-19
    • 2021-01-26
    • 1970-01-01
    • 2016-09-10
    • 2019-06-05
    • 1970-01-01
    相关资源
    最近更新 更多