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:


SharePoint Online

The cloud parts are functional components that extend your SharePoint Online environment in Microsoft 365.

Supports Classic and Modern sites for SharePoint Online/Microsoft 365

Small Business Pricing and Discounts

SharePoint

Top SharePoint Online Products

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


Calendar Plus


Chart Plus


Knowledge Base


Project Management Central


Simple List Search

 

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 2016, 2019, 2022 - Classic Pages Only

SharePoint

Top On-Premises Only Products

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


Calendar Plus


Data Viewer


Password Change


Password Expiration


Password Reset

 

Our team of Microsoft 365 experts help you get the most out of your Microsoft technology, we have the best Microsoft 365 talent to streamline your organization.

Streamline Your Department

M365 Plus

Managed Services

We Have What You Need

Federal Contractors