SharePoint 2010 Cookbook: How to Use PowerShell to Browse the SharePoint Object Model

While developing custom code for SharePoint, I’ve often run across situations where I need to quickly find the list schema, column internal name, or just the GUID of an item so I can make a decision and continue designing the code accordingly. In pre-PowerShell days I used to write NUnit code, browse to the List Settings page, or sometimes just engaged in some plain old-fashioned debugging with breakpoint, followed browsing the object in Visual Studio IDE’s watch window to find what I needed.

The good news is that with the introduction to PowerShell in general, and PowerShell for SharePoint in particular, it’s now much simpler to perform these rudimentary tasks.

Challenge:

How do I browse through the SharePoint object model using SharePoint PowerShell commands?

 

Solution:

Retrieving a value from the object model boils down to traversing the object model. The hierarchy is to get to a site collection object – SPSite – from which we get to a site object – SPWeb -from which we can get to a list collection object – SPListCollection and so on and so forth. A complete hierarchy can be seen here at the MSDN site.

Here are some steps to get you going.

Run SharePoint 2010 PowerShell console window (How?).

1- Get SPSite object in a variable. I will use the SharePoint PowerShell cmdlet Get-SPSite to get my object.

 

Or you can enumerate all sites and then pick the one you are interested in.

 

2- Get the SPWeb object in a variable. Note that I am using the object saved in $s variable above and printing out the website title. I can use many other methods and properties exposed SPWeb object.

In case you can’t remember the method or property names, just run the following command to list all public methods. And then run the above command.

Run the command without the “-membertype” switch to list all the methods and properties.

3- Get SPList object.

Caution: Don’t try to execute $w.Lists as it will go through each list in the list collection which could be very time consuming.

 

4- Dump the whole object or just a property to a file for later use

 

And finally the list schema.xml to review in IE browser ($l.SchemaXML).

 

Notes:

From the SharePoint PowerShell console window type Get-Help Get-SPSite to find out the usage and other options.

 

See also:


All SharePoint Versions

The web parts are functional components that extend your SharePoint environment whether it’s hosted, on-premises, or part of Microsoft® Office 365.

SharePoint 2013, 2016, 2019, Online (Office 365)

On-Premises Only

These web parts extend SharePoint beyond its out-of-the-box capabilities by tailoring it to your requirements with Bamboo Solution’s growing portfolio of SharePoint Web Parts.

SharePoint 2013, 2016, 2019

SharePoint

Product Suites

Experience greater power and savings by bundling our SharePoint apps and web parts.


Essentials Suite


Essentials Plus Suite


Bamboo Premier Suite


Project Management Suite


Knowledge Management Suite


External User Manager


 

For more information on our product suites, contact us.

Featured Services

SharePoint Health Check

A SharePoint Health Check will identify the causes of issues and risks associated with your specific environment, and is custom tailored to provide you with the best recommendations to optimize your SharePoint environment.

SQL Health Check

Document recommendations relating to performance, stability, availability, or a specific focus you request of your SQL Server database instances.

My SharePointXperts

The truth is that each SharePoint skill may not be a full time job for many organizations, and it is nearly impossible for one person to do everything you need – so augment your team with SharePointXperts; providing the skill sets you need when you need them!