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

[玩转系统] SharePoint Online:使用 PowerShell 隐藏内容类型

作者:精品下载站 日期:2024-12-14 14:39:56 浏览:17 分类:玩电脑

SharePoint Online:使用 PowerShell 隐藏内容类型


要求:在 SharePoint Online 中隐藏内容类型。

PowerShell 在 SharePoint Online 中隐藏内容类型:

如果您想对用户隐藏某些内容类型,或者需要暂时停止使用某种内容类型,您可以隐藏该内容类型!这篇博文将向您展示如何使用 PowerShell 隐藏内容类型。


#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"

#Config Parameters
$SiteURL="https://crescent.sharepoint.com"
$ContentTypeName="Business Contacts"

Try {
    #Get Credentials to connect
    $Cred= Get-Credential

    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
        
    #Get the content type from the web
    $ContentTypeColl = $Ctx.Web.ContentTypes
    $Ctx.Load($ContentTypeColl)
    $Ctx.ExecuteQuery()
 
    #Get the content type to Add
    $CType = $ContentTypeColl | Where {$_.Name -eq $ContentTypeName}
    If($CType -ne $Null)
    {
        $CType.Group = "_Hidden"
        $CType.Update($True)
        $Ctx.ExecuteQuery()

        Write-host "Content Type Set Hidden!" -ForegroundColor Green
    }
    else
    {
        Write-host "Content Type Doesn't Exist!" -ForegroundColor Yellow
    }
}
Catch {
    write-host -f Red "Error Hiding the Content Type!" $_.Exception.Message
}

这会将内容类型移至隐藏组 - 这会从网站设置 >> 网站内容类型页面隐藏内容类型!此外,当您尝试将任何现有内容类型添加到列表或库时,此内容类型不会列在可用内容类型下拉列表中。

PnP PowerShell 在 SharePoint Online 中隐藏内容类型

在某些情况下,您可能希望隐藏内容类型以防止用户意外使用它,或简化用户体验。让我们看看如何使用 PnP PowerShell 在 SharePoint Online 中隐藏内容类型。


#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Retail"
$ContentTypeName = "Crescent Contacts"

#Connect to SharePoint Online Site
Connect-PnPOnline -Url $SiteURL -Interactive

#Get the Content Type
$ContentType = Get-PnPContentType -Identity $ContentTypeName

#Hide the Content type
$ContentType.Group = "_Hidden"
$ContentType.Update($true)
Invoke-PnPQuery

若要从 SharePoint Online 列表设置页面的新按钮下拉列表中隐藏内容类型,请使用:SharePoint Online:从下拉列表中隐藏内容类型

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

取消回复欢迎 发表评论:

关灯