There is already a script on my blog which lists the site structure for SharePoint Online but I also created a script to get all content types and columns with PowerShell for SharePoint Online. The script will do the following:

– Get all content types for each site collection in SharePoint Online

– Get columns associated with each content type in SharePoint Online

– collect this information and store this in an HTML table

The script will generate the following output:


You will need to install the SharePoint Online Management Shell from and all of its pre-requisites. The below script needs to be copied to a .ps1 file on the workstation you are planning to run this script. It will create a logfile on the same location.

function connectToO365{
# Let the user fill in their admin url, username and password
$adminUrl = Read-Host "Enter the Admin URL of 0365 (eg. https://<Tenant Name>"
$userName = Read-Host "Enter the username of 0365 (eg. admin@<tenantName>"
$password = Read-Host "Please enter the password for $($userName)" -AsSecureString
# set credentials
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $password
$SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $password)
#connect to to Office 365
Connect-SPOService -Url $adminUrl -Credential $credentials
write-host "Info: Connected succesfully to Office 365" -foregroundcolor green
write-host "Error: Could not connect to Office 365" -foregroundcolor red
Break connectToO365
#create HTML file
$filePath = create-outputfile
#start getting site collections
add-content -value "
" -path $filePath
function create-outputfile(){
#Create unique string from the date
$date = get-date -format dMMyyyyhhmm
#set the full path
$filePath = "$($PSScriptRoot)\Output$($date).html"
#test path
if (!(Test-Path -path $filePath)){
#create file
New-Item $filePath -type file | out-null
#print info
write-host “File created: $($filePath)” -foregroundcolor green
#add start HTML information to file
add-content -value "
<h1>Content Types and Columns in Office 365</h1>
<table border='1' style='font-family: Calibri, sans-serif'>
<th style='background-color:blue; color:white'>Site Collection</th>
<th style='background-color:blue; color:white'>Content Type</th>
<th style='background-color:blue; color:white'>Columns</th>
" -path $filePath
#break so there won't be duplicate files
write-host "Output file already exists, wait 1 minute" -foregroundcolor yellow
Break create-outputfile
return $filePath
function get-siteCollections{
#Get all site collections
$siteCollections = Get-SPOSite
#loop through all site collections
foreach ($siteCollection in $siteCollections)
#add info to HTML document
add-content -value "<tr style='background-color:orange'><td>$($siteCollection.url)</td><td></td><td></td></tr>" -path $filePath
write-host "Info: Found $($siteCollection.url)" -foregroundcolor green
#get content type information for each site collection
function Get-SPOContentTypes($url){
#fill metadata information to the client context variable
$context = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$context.Credentials = $SPOcredentials
$web = $context.Web
#loop through all content types in the site collection
foreach($ct in $web.ContentTypes){
#skip hidden content types
if ($ -ne "_hidden")
add-content -value "<tr style='background-color:yellow'><td></td><td>$($</td><td></td></tr>" -path $filePath
#get columns of content type
get-SPOColumns $ct
write-host "Info: Found $($i) content types" -foregroundcolor green
write-host "Could not load content types" -foregroundcolor red
function Get-SPOColumns($ct){
#get column information from the variable
foreach($ctColumn in $ct.fields){
#skip content type entry for each content type
if ($ctColumn.Title -ne "Content Type"){
#skip hidden columns
if ($ctColumn.hidden -ne $true){
add-content -value "<tr style='background-color:lightyellow'><td></td><td></td><td>$($ctColumn.title)</td></tr>" -path $filePath
write-host "Info: Found $($j) columns in $($" -foregroundcolor green
write-host "Could not load columns" -foregroundcolor red



This script has been run on a workstation with Windows 8.1. First run the SharePoint Online Management Shell as administrator

SharePoint Online Management Shell logo.

Then run the following command

& “script location”


And answer the following three questions


And press enter


All content types and columns have been successfully crawled and its contents is listed in the HTML document located next to the .ps1 file


You can list more information if you want and you can find the properties on the following locations:

– SPOSite properties:

– Web properties:

Let me know if you have any remarks or updates

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.