Búsqueda de sitios web

SharePoint Online: establezca el tipo de contenido en solo lectura usando PowerShell


Requisito: Hacer que el tipo de contenido sea de solo lectura en SharePoint Online.

¿Cómo hacer que un tipo de contenido sea de solo lectura en SharePoint Online?

En SharePoint Online, puede hacer que un tipo de contenido sea de solo lectura para evitar que los usuarios lo editen. Esto puede resultar útil si desea restringir quién puede modificar un tipo de contenido en particular o si desea garantizar que los datos sean coherentes. Este artículo le mostrará cómo hacer que un tipo de contenido sea de solo lectura en SharePoint Online.

Para configurar un tipo de contenido como de solo lectura, haga lo siguiente:

  1. Vaya a Configuración >> Configuración del sitio >> Haga clic en el enlace "Tipos de contenido del sitio"
  2. De los tipos de contenido enumerados, haga clic en el nombre del tipo de contenido.
  3. Vaya a Configuración avanzada en la página de configuración del tipo de contenido.
  4. Establezca "Sí" en ¿Debería este tipo de contenido ser de solo lectura?

SharePoint Online: PowerShell para establecer el tipo de contenido en solo lectura

¿Qué sucede si necesita configurar el tipo de contenido para que solo se lea mediante secuencias de comandos? Déjame mostrarte cómo usar PowerShell para configurar el tipo de contenido en solo lectura:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\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.ReadOnly=$True
        $CType.Update($True)
        $Ctx.ExecuteQuery()

        Write-host "Content Type is Set to Read Only!" -ForegroundColor Green
    }
    else
    {
        Write-host "Content Type Doesn't Exist!" -ForegroundColor Yellow
    }
}
Catch {
    write-host -f Red "Error Setting Content Type to Read Only!" $_.Exception.Message
} 

PnP PowerShell para hacer que un tipo de contenido sea de solo lectura:

Configurar un tipo de contenido como de solo lectura en SharePoint Online puede resultar útil cuando desea evitar que los usuarios realicen cambios en tipos de contenido específicos, como documentos o registros importantes. A continuación se explica cómo configurar un tipo de contenido para que sea de solo lectura usando PnP PowerShell.


#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$ContentTypeName ="Crescent Invoice Template V2"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get the Client Context
$Context = Get-PnPContext
 
#Get the content type from site
$ContentType = Get-PnPContentType -Identity $ContentTypeName

If($ContentType)
{
    #Set the Content type to Read Only
    $ContentType.ReadOnly = $True
    $ContentType.Update($False) #Update children
    $Context.ExecuteQuery()

    Write-host -f Green "Content Type '$ContentTypeName' is Set to Read Only!"
}

También podemos configurar el tipo de contenido en solo lectura en el nivel de lista:


#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$ContentTypeName ="Crescent Invoice Template V2"
$ListName ="Team Documents"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get the Client Context
$Context = Get-PnPContext
 
#Get the content type from List
$ContentType = Get-PnPContentType -Identity $ContentTypeName -List $ListName

If($ContentType)
{
    #Set the Content type to Read Only
    $ContentType.ReadOnly = $True
    $ContentType.Update($False) #Update children
    $Context.ExecuteQuery()

    Write-host -f Green "Content Type '$ContentTypeName' is Set to Read Only!"
}

Artículos relacionados