SharePoint Online: encuentre quién creó una lista o biblioteca usando PowerShell
Requisito: Buscar quién ha creado una lista o biblioteca en SharePoint Online.
Obtenga quién ha creado una biblioteca en SharePoint Online:
Si desea saber quién ha creado una lista o biblioteca de SharePoint Online: Lo sentimos, ¡no hay forma desde la interfaz de usuario web de SharePoint! No puede obtener el valor "Creado por" en ninguna parte. La capacidad de encontrar rápidamente al creador de una lista o biblioteca de SharePoint Online puede ser una pieza fundamental de la información de auditoría o solución de problemas. ¡Por lo tanto, PowerShell puede ayudar a encontrar esta información rápidamente!
SharePoint Online: busque quién creó una lista usando PowerShell
Aún no tenemos una propiedad List.Author expuesta en CSOM. Sin embargo, podemos extraer información del autor de SchemaXML de la lista.
#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"
#Function to call a non-generic method Load
Function Invoke-LoadMethod()
{
param([Microsoft.SharePoint.Client.ClientObject]$Object,[string]$PropertyName)
$ctx = $Object.Context
$load = [Microsoft.SharePoint.Client.ClientContext].GetMethod("Load")
$type = $Object.GetType()
$clientLoad = $load.MakeGenericMethod($type)
$Parameter = [System.Linq.Expressions.Expression]::Parameter(($type), $type.Name)
$Expression = [System.Linq.Expressions.Expression]::Lambda([System.Linq.Expressions.Expression]::Convert([System.Linq.Expressions.Expression]::PropertyOrField($Parameter,$PropertyName),[System.Object] ), $($Parameter))
$ExpressionArray = [System.Array]::CreateInstance($Expression.GetType(), 1)
$ExpressionArray.SetValue($Expression, 0)
$clientLoad.Invoke($ctx,@($Object,$ExpressionArray))
}
#Function to get user who created a SharePoint Online List or library
Function Get-SPOListAuthor($SiteURL,$ListName)
{
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 List
$List=$Ctx.Web.Lists.GetByTitle($ListName)
$Ctx.Load($List)
$Ctx.ExecuteQuery()
#Get List Schema XML
Invoke-LoadMethod -Object $List -PropertyName "SchemaXML"
$Ctx.ExecuteQuery()
#Extract Author from List Schema XML
$ListSchema = [xml] $List.SchemaXml
$AuthorID = $ListSchema.List.Author
$Author = $Ctx.web.GetUserById($AuthorID)
$Ctx.Load($Author)
$Ctx.ExecuteQuery()
Return $Author
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
}
#Set Parameters
$SiteURL="https://Crescent.sharepoint.com"
$ListName="Documents"
Get-SPOListAuthor -SiteURL $SiteURL -ListName $ListName
Actualización: La versión reciente del CSOM expone la propiedad List.Author a través de sus API. Ahora es posible recuperar la propiedad de autor de una lista de SharePoint Online directamente. P.ej.
#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/sites/Marketing"
$ListName="Projects"
#Setup Credentials to connect
$Cred = Get-Credential
Try {
#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 List Author
$Web=$Ctx.Web
$List= $Web.Lists.GetByTitle($ListName)
$Ctx.Load($List)
$Ctx.Load($List.Author)
$Ctx.ExecuteQuery()
Write-host -f Green $List.Author.Email
}
Catch {
write-host -f Red "Error: " $_.Exception.Message
}
Encuentre quién ha creado una biblioteca de documentos usando PnP PowerShell
¿Necesita determinar quién creó una lista en su sitio de Sharepoint Online? ¡Aquí está el PnP PowerShell para comprobarlo!
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$ListName = "Branding"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get the List
$List = Get-PnPList -Identity $ListName -Includes Author
#Get the author of the list
$List.Author | Select Title, Email
