How to audit SharePoint using powershell

Sometimes you need to know what information you have got in your SharePoint solution. I have been asked this numerous times since GDPR was introduced.

PowerShell
Get-SPWeb http://your-sharepoint-site |
    Select -ExpandProperty Lists |
    Where-Object { 
        $_.GetType().Name -eq "SPDocumentLibrary" -and -not $_.Hidden 
    } |
    Select -ExpandProperty Items |
    Group-Object {
        $_.ParentList.ParentWeb.Url + "/" + $_.ParentList.Title
    } |
    Select-Object Name, Count |
    Format-Table -AutoSize

This PowerShell command is designed to work with SharePoint, and its main purpose is to list the items in SharePoint document libraries that are not hidden. Let’s break it down step by step:

  1. Get-SPWeb http://your-sharepoint-site:
    • This cmdlet retrieves a specific SharePoint web (a site) based on the given URL.
  2. Select -ExpandProperty Lists:
    • This takes the SharePoint web retrieved from the first command and expands its “Lists” property. Essentially, it fetches all the lists (and libraries, since in SharePoint a document library is technically a type of list) present on the given SharePoint web.
  3. Where-Object { $.GetType().Name -eq “SPDocumentLibrary” -and -not $.Hidden }:
    • This filters the results from the previous command. It only selects those objects that are of type “SPDocumentLibrary” (meaning they’re document libraries) and are not hidden.
  4. Select -ExpandProperty Items:
    • This takes each of the filtered document libraries and expands their “Items” property, meaning it fetches all the individual items (like documents) within each library.
  5. Group-Object { $.ParentList.ParentWeb.Url + “/” + $.ParentList.Title }:
    • This groups the resulting items by their parent list’s web URL and title. The purpose of this is likely to aggregate the items based on which library (and its location) they come from.
  6. Select-Object Name, Count:
    • From the grouped results, this command selects the name of the group (which is the library’s web URL and title from the previous command) and the count of items within that group.
  7. Format-Table -AutoSize:
    • Finally, this formats the results into a table, adjusting the column sizes to fit the content (due to -AutoSize).

In summary, the command fetches all items from non-hidden document libraries in a given SharePoint web, groups them by their parent library’s location and title, and then displays a table showing how many items are in each of these libraries.

Elsewhere On TurboGeek:  Installing and Using the Alation Data Catalog

Richard.Bailey

Richard Bailey, a seasoned tech enthusiast, combines a passion for innovation with a knack for simplifying complex concepts. With over a decade in the industry, he's pioneered transformative solutions, blending creativity with technical prowess. An avid writer, Richard's articles resonate with readers, offering insightful perspectives that bridge the gap between technology and everyday life. His commitment to excellence and tireless pursuit of knowledge continues to inspire and shape the tech landscape.

You may also like...

1 Response

  1. 01/07/2022

    […] Remember, you can embed PowerShell commands into sharepoint. […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate ยป