Tuesday 23 July 2019

How to check who created view in SharePoint online


How to check who created list view in SharePoint online document library/ list

You cannot get the information who a view created because it's not cover by the object model. The  object doesn't store a property for modified or created. To get the information all you can do is to get the information from the file. So for the view url you need to request the file url****.aspx.
The file object stores the "Author", "TimeCreated", "Modified" and "Modified by" values.
The PowerShell Script looks like this:

# Load required dlls
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.DocumentManagement")


$SiteUrl = "https://Yourtenent.sharepoint.com/sites/sitename"
$viewurl = "https://Yourtenent.sharepoint.com/sites/sitename/Shared%20Documents/Forms/Custom.aspx"

$sUserName="admin@Yourtenent.onmicrosoft.com" 
$securePassword= ConvertTo-SecureString "your password" -asplaintext -force
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUserName, $securePassword)

$spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$spoCtx.Credentials = $Credentials      
$spoCtx.RequestTimeOut = 5000 * 60 * 10;
$web = $spoCtx.Web
$site = $spoCtx.Site
$spoCtx.Load($web.Webs)
$spoCtx.Load($site)
$spoCtx.ExecuteQuery()
Write-Host "connected successfully"
$targetUrl =$web.GetFileByUrl("https://Yourtenent.sharepoint.com/sites/learninghub/Shared%20Documents/Forms/Custom.aspx")

$spoCtx.Load($targetUrl)
$spoCtx.Load($targetUrl.Author)
$spoCtx.ExecuteQuery()
Write-Host "View: $($targetUrl.Name)"
Write-Host "Author $($targetUrl.Author.UserPrincipalName)"
Write-Host "Created On: $($targetUrl.TimeCreated)"