PowerShell: How to See SharePoint Object Property Values In Order
John E. Huschka, August 31, 2017
Wouldn't it be great if we could see all the property names and values of our SharePoint objects together—in order?
As a SharePoint/O365 administrator and developer, I spend a lot of time in PowerShell. And there are some challenges that I keep running into:
- I know the value of a UI-displayed setting, but I don’t know what object property contains the value.
- I know that there is a property available on an object, but I am not sure what it is called or its current value.
- I have an object that I suspect might contain a certain property that I need, but I'm not sure of the property’s name.
Collaboration Foundry has developed the PowerShell scripts in this post to address these SharePoint challenges, one for on‑premise and one for Office 365 (the cloud).
We are going to use site collections in our examples, but the core script functionality will work for any SharePoint object.
SharePoint On-Premise
Our on-premise code (provided below) uses the server-side PowerShell snap-in to interact with SharePoint.
The core of the code is the DumpObjectProperties function to which an object is passed as a parameter ( $objectToDump).
Given the object, the DumpObjectProperties function:
- First uses the Get-Member cmdlet to get all property names of the object.
- Then uses the Sort-Object cmdlet to sort the property names into alphabetical order, into a string array.
- Then passes the string array with property names into Format-List, which displays the name and value of all properties.
This results in output like this: (“~” indicates omitted output.)
Collaboration Foundry has provided the complete source code for this server-side solution at https://github.com/FoundryFounder/PowerShell/tree/master/DumpSiteCollectionsServerSide.
SharePoint Office 365
Our client-side SharePoint Office 365 (cloud) code (provided below) must address a few more challenges than the server-side code:
- There are actually two site collection objects within SharePoint Office 365: One is the object that we see displayed in the SharePoint admin center (shown below) and the other is analogous to on-premise SharePoint’s site collection object. We are going to show the properties of both.
- When we Load and ExecuteQuery on an object, properties for which the value is a collection are not automatically retrieved. We must do another Load and ExecuteQuery for each collection-valued property.
- When retrieving some of the collection properties using Load and ExecuteQuery, we occasionally experience permission errors. Therefore, we are loading one at a time so that an error associated with property x does not prevent us from retrieving property y’s value.
- Finally, within the client-side programming model, an object’s property may not have been retrieved from the server and initialized. This will cause the Format-List we use to display property values to raise an exception. For this reason, we have isolated the Get-Member property name retrieval from the Format-List property value display in the DumpObjectProperties function. Now Format-List is called once for each property, allowing us to handle an uninitialized property exception with each property value display.
Note that this script requires the SharePoint Online CSOM libraries and the SharePoint Online Management Shell PowerShell module.
Sample output from this script is displayed below. One of the advantages of the script is that it displays the values of O365 group-associated site collections that are not otherwise available within the administrative user interface. (“~” indicates omitted output.)
Collaboration Foundry has provided the complete source code for this client-side solution at https://github.com/FoundryFounder/PowerShell/tree/master/DumpSiteCollectionsClientSide.
We at Collaboration Foundry are experts in SharePoint, Office 365, and PowerShell. If you need assistance, we can help. Contact us.