SharePoint: iterate all pages in site collection (PowerShell)

If you ever need to loop through all pages in a given SharePoint site collection, you might take a look at the PowerShell script below. While iterating through all aspx pages might be a rare need, I found it useful when I had to set some properties for WebParts through SPLimitedWebPartManager API. If you have some other idea how to use it, feel free to try this code 🙂

It crawls through the SharePoint site collection using it’s object model, and adds URL’s of pages to an array. With a little modification, the code might be limited to a scope of a SPWeb, or just views of a particular list.

When the iteration is done, all URL’s are stored in $urls variable and can be used in some custom business logic.