2

I am trying to come up with a script to do the following in my SharePoint 2013 environment, and have not had much luck.

I need a script that will generate a report/csv that will list all items in lists where a site column has a specific value.

For example, say I have a site collection at http://test/site, and a site column named "State." That column is used in multiple lists throughout my site collection. I need to generate a report which shows all instances of items where State Column = Texas.

Thanks for any help you can provide.

5

I haven't tested this, but I imagine your solution would look something like this

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

[Microsoft.SharePoint.SPSite] $site = Get-SPSite http://test/site

foreach ($web in $site.AllWebs)
{
    foreach ($list in $web.Lists)
    {
        if ($list.Fields.ContainsField("State"))
        {
            foreach ($item in $list.Items)
            {
                if ($item["State"] -eq "Texas")
                {
                    # Log in file, or something similar
                    Add-Content -Path e:\output.txt -Value $item["EncodedAbsUrl"]
                }
            }
        }
    }
}
  • Thanks. I tried this and it created the output.txt file, but after running for a while the script completed and the file is empty. I did confirm there are items which have the field and value that match the criteria. Thanks for any additional assistance you can provide. The only things I changed in your example was match the site/column data to match my environment, and then replaced the comment with Out-File e:\output.txt. Thanks for your help. – THTX Jan 21 at 16:20
  • See my edit for a possible solution. It should log the URL of the item, which will give you the list URL and item ID. That should be enough, but if you need more you can extract it from the variables at your disposal ($item, $list, $web). – baconbum Jan 22 at 16:48
0

If you want that report to be available to the end user or admins a search based approach could be an option ( security trimmed out of the box) : Map the crawled property to a managed property, wait for the next full crawl, and now you can either create a search resultat source for that specific purpose or just use the search center for ad hoc queries

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.