Introduction
We discussed and show cased few PowerShell and CSOM functionalities in earlier blogs. Please refer to the links below
In Part 3 we showed the steps to add Format files for our Script module and in this article we will demo an alternate method to Add custom view for our objects without creating PSOject explicitly and this is just a tip to get List Property information. Do remember we are using CSOM and PowerShell and there are high chances of performance issues which will be addressed in later upcoming blog articles. For, now we will cover alternate options.
Code at Ease
process { $SPOClientContext = [Microsoft.SharePoint.Client.ClientContext]::new($Url) $SPOClientContext.Credentials = $Credential $ListCollection = $SPOClientContext.Web.Lists $SPOClientContext.Load($ListCollection) $SPOClientContext.ExecuteQuery() $SPOClientContext.Dispose() foreach($List in $ListCollection) { $List.PSOBject.TypeNames.Insert("0" , "SharePointOnline.Format.Custom.ListView") $List } }
What we did here is a very simple and ugly way of getting List Information and created a default view using Format.ps1xml. The advantage is we will allow users to select the required properties! So, no need to type all properties names and keeps the code neat and clean. Again! Please ignore the performance we will discuss about it soon. This function takes maximum 4 seconds and 1 second minimum to query.
Output
Well! It looks good for now! Let’ test it with different properties
Get-xSPOList -Url https://chensoffice365.sharepoint.com | Select -First 5 | Select Title , NoCrawl Get-xSPOList -Url https://chensoffice365.sharepoint.com | Select -First 5 | Select Title , NoCrawl , Hidden