Share via


SharePoint Online: Get any object with PowerShell - lists, libraries, items, and files (Part 2)

The examples below require a PowerShell module available here on TechNet Gallery.

As discussed in Get any SharePoint Online object with Powershell, REST API endpoints allow us to interact with sites remotely. The examples below use these possibilities and together with a single cmdlet from a PowerShell module pull useful data, troubleshoot your tenant and create reports in a way that is not possible with SharePoint Online Management Shell.

Lists

Get the number of items in every list

Get-SPOObject -Username t@t321.onmicrosoft.com -password $pass -Url "https://t321.sharepoint.com/polski" -Object "web/lists" | select title, itemcount

or

Get-SPOObject -Username t@t321.onmicrosoft.com -password $pass -Url 'https://t321.sharepoint.com' -Object 'web/lists?$select=title,itemcount'

Get all hidden columns in a list called "lista"

Get-SPOObject -Username t@t321.onmicrosoft.com -password $pass -Url "https://t321.sharepoint.com/polski" -Object "web/lists/getbytitle('lista')/fields" | where {$_.Hidden -eq $true} | select staticname, id

Get all columns visible to the users in a list called "lista"

Get-SPOObject -Username t@t321.onmicrosoft.com -password $pass -Url "https://t321.sharepoint.com/polski" -Object "web/lists/getbytitle('lista')/fields" | where {$_.Hidden -eq $false} | select staticname, id

Get all lookup columns in a list

Get-SPOObject -Username t@t321.onmicrosoft.com -password $pass -Url "https://t321.sharepoint.com/polski" -Object "web/lists/getbytitle('lista')/fields" | where {$_.TypeAsString -eq "Lookup"} | select staticname, lookupfield, lookuplist

Get all hidden lists

Get-SPOObject -Username t@t321.onmicrosoft.com -password $pass -Url 'https://t321.sharepoint.com' -Object 'web/lists' | where {$_.Hidden -eq $true } | select title, id

Get all list content types

Get-SPOObject -Username t@t321.onmicrosoft.com -password $pass -Url 'https://t321.sharepoint.com' -Object "web/lists/getbytitle('lista')/contenttypes"

Get-SPOObject -Username t@t321.onmicrosoft.com -password $pass -Url 'https://t321.sharepoint.com' -Object "web/lists/getbytitle('lista')/contenttypes" | select name, scope, readonly, hidden, stringid

Libraries

Get all files from the library

Get-SPOObject -Username t@t321.onmicrosoft.com -password $pass -Url 'https://t321.sharepoint.com' -Object "web/lists/getbytitle('biblioteka')/files"

Get files greater than and export their names to a CSV

Get-SPOObject -Username t@t321.onmicrosoft.com -password $pass -Url  'https://t321.sharepoint.com' -Object "web/lists/getbytitle('biblioteka')/files" | where {$_.Size -gt 500000}  | export-csv c:\files.csv

Find the number of lists per templates

Finds how many tasks lists, how many surveys, how many custom lists or how many libraries there are:

Get-SPOObject -Username t@t321.onmicrosoft.com -password $pass -Url  'https://t321.sharepoint.com' -Object "web/lists/" |  group basetemplate

Find lists or libraries with a certain content type

$ContentTypeID="0x00A7470EADF4194E2E9ED1031B61DA08840300354E22580AD3B14AB07D9B324713A872"
$lists=(Get-SPOObject -Username t@t321.onmicrosoft.com -password $pass -Url  'https://t321.sharepoint.com' -Object "web/lists")
foreach($list in  $lists){Get-SPOObject -Username t@t321.onmicrosoft.com -password $pass -Url  'https://t321.sharepoint.com' -Object ("web/lists/getbytitle('"+$list.Title +"')/contenttypes") | where {$_.StringId -match $ContentTypeID} | select Scope}

Downloads

See Also

Back to Top