Today, I wanted to get a full overview of all the Microsoft Teams teams sites that I have in my tenant. I decided to put PnP PowerShell to the test for this.
I found that Get-PnPTenantSite didn’t include my team sites and therefore I had to look for different options. Quite quickly I found a solution. I had to go through the following steps:
- Connect to my SharePoint Admin Center site.
- Get a list called: DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS
- Display the list items in this list
Connecting to the Admin Center site
To connect to the Admin Center site I’m running the following command:
[code lang=text]
Connect-PnPOnline https:/ /mytenant-admin.sharepoint.com
[/code]
Get the list
First I need to get the site. Then I load my lists just to have a look at which lists exist:
[code lang=text]
$site = Get-PnPSite
$site.Context.Load( $site.RootWeb)
$site.Context.ExecuteQuery()
$web = $site.RootWeb
$site.Context.Load( $web.Lists)
$site.Context.ExecuteQuery()
[/code]
Now a quick look at $web.Lists shows me that there is a list with a very long name: DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS
Not sure who came up with this name for a list. But it is very noticeable.
Now I get my list:
[code lang=text]
$list = $web.Lists[5]
[/code]
Display The List Items
Ok, we are nearly there. Just get all the list items and spit out the SiteUrl
[code lang=text]
for ($x = 0; $x -lt $list.ItemCount; $x++ )
{
$item = $list.GetItemById($x)
$site.Context.Load( $item)
$site.Context.ExecuteQuery()
Write-Host $item.FieldValues.SiteUrl : $item.FieldValues.TemplateTitle
}
[/code]
Yes I know I could clean up the above code a bit. e.g. use a Query and query the list for the list items. But for simplicity I kept the code as simple as possible.
Ok, So now I’ve got all of my site collections listed with their templates used. All the sites marked Team site are my modern team sites.
So now we need to find a way to filter out the Modern Team sites that were created within SharePoint rather than Microsoft Teams. ( Thanks Paul Keijzers for pointing this out
!). Unfortunately there isn’t an option for this yet!
[…] https://veenstra.me.uk/2017/11/03/microsoft-teams-get-all-your-team-sites-using-pnp-powershell […]
[…] last weeks post Microsoft Teams – Get all your team sites using PnP Powershell, Now my next attempt with the all new Microsoft Teams […]
I tried to get the list items using the mentioned script. but did not get any output — what went wrong?
So after you run :
Connect-PnPOnline https://mytenant-admin.sharepoint.com
$site = Get-PnPSite
$site.Context.Load( $site.RootWeb)
$site.Context.ExecuteQuery()
$web = $site.RootWeb
$site.Context.Load( $web.Lists)
$site.Context.ExecuteQuery()
When you then run:
Write-Host $web.Lists
Do you get any lists returned?
running $web.Lists returns:
PS C:\WINDOWS\system32> $web.Lists
Title Id Url
—– — —
appdata bbe2353d-d36a-4f9f-b9dd-9e3cb055f605
appfiles 42f2eafe-2ca2-4cb1-9212-6546020a1d65
Durchkomponierte Looks e4bb8bc6-7637-4df5-a522-850f90aaf860
Fehlerprotokoll für die Inhaltstypveröffentlichung 41f93a5d-38b4-45ef-be16-96ce85ccf773
Konvertierte Formulare 46fc4c27-489c-4719-909e-77307fa55520
DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS 163b58bd-6d7a-44fb-a98d-7af1872fc072
ExtranetInvitationStatusList ee316473-748e-47e9-a675-cbacd7cd2bb1
Formularvorlagen 1703d8cb-edb0-4806-9c89-9fae2d1e4d7b
Listenvorlagenkatalog c30df519-064d-4765-b7f6-c4838b1c9f27
Wartungsprotokollbibliothek f08883e3-ec55-4189-b8dd-dfdd5de26783
Gestaltungsvorlagenkatalog 97e2c6c7-fa83-4055-980a-aebde35cfa4d
Suchkonfigurationsliste 8f70c86f-460f-4e39-975a-5cd4305af7c6
Lösungskatalog 664ce078-7546-4cb4-89ea-ec72e1a8369e
Formatbibliothek 86998856-0b82-41d0-9ebf-564b78f2a56b
TaxonomyHiddenList 9e81c72e-89fe-49bc-bcb0-b17f2053b94f
Designkatalog 1f935dd8-1960-4b5b-b870-59347316d805
Benutzerinformationsliste 64fc64bc-1cae-4e80-a272-9f4cf0aeb80f
Webpartkatalog 2d7e08a8-7e9f-48d7-8aa9-8888140ae5da
but running Write-Host — returns the below?
PS C:\WINDOWS\system32> Write-Host $web.Lists
Microsoft.SharePoint.Client.List Microsoft.SharePoint.Client.List Microsoft.SharePoint.Client.List Microsoft.SharePoint.Client.
List Microsoft.SharePoint.Client.List Microsoft.SharePoint.Client.List Microsoft.SharePoint.Client.List Microsoft.SharePoint.Cl
ient.List Microsoft.SharePoint.Client.List Microsoft.SharePoint.Client.List Microsoft.SharePoint.Client.List Microsoft.SharePoi
nt.Client.List Microsoft.SharePoint.Client.List Microsoft.SharePoint.Client.List Microsoft.SharePoint.Client.List Microsoft.Sha
rePoint.Client.List Microsoft.SharePoint.Client.List Microsoft.SharePoint.Client.List
I just realised that the following code could fail.
Can you check you $list.ItemCount? The above assumes that you don’t have any site collection that were deleted. If you get the $list.ItemCount then we can see how many items there are in the list.
Also Try running Get-PnPListItem -List $list
That should return all items in the list.
Hi Pieter
for what ever reason I got some output now — with an error – -but an output.
If you allow me to ask — all the stuff I am trying is to find a way to use MS Teams with SPO behind and using a “template” which I ca precustomize before I create the “Team” — e.g. Doc Library — Metadata stuff etc. — And my aim was to find the “Master template Teams is using”
Any idea for this? thx in advance
PS C:\WINDOWS\system32> $list = $web.Lists[5]
PS C:\WINDOWS\system32> for ($x = 0; $x -lt $list.ItemCount; $x++ )
{
$item = $list.GetItemById($x)
$site.Context.Load( $item)
$site.Context.ExecuteQuery()
Write-Host $item.FieldValues.SiteUrl : $item.FieldValues.TemplateTitle
}
Ausnahme beim Aufrufen von “ExecuteQuery” mit 0 Argument(en): “Das Element ist nicht vorhanden. Möglicherweise wurde es von
einem anderen Benutzer gelöscht.”
In Zeile:6 Zeichen:1
+ $site.Context.ExecuteQuery()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ServerException
:
https://akte8.sharepoint.com : Team site (classic experience)
https://akte8.sharepoint.com/sites/windowsapps : Team site
https://akte8.sharepoint.com/portals/Community : PointPublishing Topic
https://akte8.sharepoint.com/sites/Development : Team site
https://akte8.sharepoint.com/sites/HRSteven : Team site
https://akte8.sharepoint.com/sites/HRSteffi : Team site
https://akte8.sharepoint.com/sites/intern : Team site
https://akte8.sharepoint.com/sites/intern : Team site
https://akte8-my.sharepoint.com : My Site Host
https://akte8-admin.sharepoint.com : Tenant Admin Site
https://akte8.sharepoint.com/sites/CompliancePolicyCenter : Compliance Policy Center
https://akte8.sharepoint.com/sites/contentTypeHub : Team site (classic experience)
https://akte8.sharepoint.com/search : Enterprise Search Center
https://akte8.sharepoint.com/portals/hub : PointPublishing Hub
https://akte8.sharepoint.com/sites/akte8 : Team site
https://akte8.sharepoint.com/sites/privat : Team site
https://akte8.sharepoint.com/sites/olli_doc-test : Team site
https://akte8.sharepoint.com/sites/office_add-ins : App Catalog Site
https://akte8.sharepoint.com/sites/stammdaten : Team site
https://akte8.sharepoint.com/sites/testdocs : Team site
https://akte8.sharepoint.com/sites/Akte8Admin : Team site
https://akte8.sharepoint.com/sites/HansMustermann : Team site
https://akte8.sharepoint.com/sites/Akte8Auswertung : Team site
https://akte8.sharepoint.com/ : Team site (classic experience)
https://akte8.sharepoint.com/sites/msteams_652760 : Team site
https://akte8.sharepoint.com/sites/msteams_36aee3 : Team site
PS C:\WINDOWS\system32> Get-PnPListItem -List $list
Id Title GUID
— —– —-
1 Akte 8 Team Site 192b3c1c-9726-4a4f-bad7-3fe24cd20418
2 windowsapps a6fbd985-beab-4f8d-ac7d-8865c37061d1
3 Community 1b181f4f-e890-4cbc-9ad8-0a9d6f209c05
4 Development fd2b8282-5766-43da-9e4d-621fdf8ea62a
5 HR Steven d102b0df-c671-45d0-9e00-afda777031d5
6 HR Steffi e4f7fb28-16f3-49dc-b9dd-667d9e9298be
7 intern 559f7f53-5c6d-46b4-8b70-9c5ec99f93e4
8 intern 1bef2a19-7227-4f34-869d-a49cd69802ce
9 936e3e36-88de-4f69-a46d-7381b9e911a8
10 Tenant Administration 2552f498-8fc0-4963-b752-e5bd3599ecb9
11 Site Based Retention acd8a2e7-7d3f-4dbd-a32e-c9b31812a042
12 Team Site d55bf1b3-0808-43ff-9b5a-56e0edeec5a8
13 92510841-3d0a-4845-bc38-ef13d0fe61b1
14 PointPublishing Hub Site 709c0133-ee8b-48f1-8d21-dc2fc7b29557
15 akte8 cf397f61-c177-4ac9-bc62-284f8b0a47f6
16 privat d7e94145-c8cf-48df-b576-80554ea31b95
17 olli_doc-test 978943e1-47e3-42d3-a054-82c1afc0bef8
18 Office Add-Ins 6f871349-2ce8-464d-aad8-4ab7908629df
19 Stammdaten f293455f-b9e5-430d-92e7-f77deae0643e
20 testdocs ae577542-a6f6-4d5e-bc52-5e5282c29d88
21 Akte8 Admin ec345a88-0087-4809-8055-027081473e78
22 Hans Mustermann ./. Oliver Test 3f0f48f3-b02c-488b-98fd-023e161bd492
23 Akte8 Auswertung 7deefd88-5de4-4048-9c14-f500ea3eb120
24 Akte 8 Team Site 97964061-9862-49a5-a307-b017f73d231d
25 0001 c1d9d697-fbe6-4156-a76f-b61d0bfc3d56
26 0002 1ee17bcd-e217-49d8-a5ee-97d0ca1754b7
27 0003 c45e41a1-1f18-4bd0-b861-2feb5c4fef2c
28 0004 eb52e9d3-05f4-4494-b64c-bb38903ab5c3
29 0005 e95fa92c-9430-4b01-9da0-e2033942683a
30 0006 4b01e2a9-da2e-4077-adb4-c99577ecc009
31 0007 c5d02a37-fdc4-4e63-9d01-5adcd6144e81
32 0008 3babe342-15ae-4735-aeb2-269aa5786e08
33 0009 e6df2f54-5922-432c-802b-d58be17c8e8d
34 0011 b1580bec-8906-4f5a-aa82-fd4cfceb6076
35 0012 3dec55f7-04a6-4f4f-996b-360deb3754b8
36 0013 cf6b5c63-666a-426a-9222-76b2fc986f1e
37 0014 12db0bb9-0a5d-44a2-9e51-0975210e45b2
38 0010 4c72861b-fa5e-4722-adda-d87f47530745
39 0015 e987f717-925e-412e-ad99-065c2b9df1c2
40 0016 8f8b11b2-b510-4950-a9a5-385413fa5f6e
41 0017 7b513906-eb2f-4ccc-88b9-3ff7abf9e2f6
42 0018 8254aed3-022b-4db1-bbf2-a71c9fdef2aa
43 0019 71477c76-b763-41e9-91b2-a8b4b78b8d13
44 0020 755676e7-229e-4a75-aefc-a2a1844d629c
45 0021 3f8b6ab6-d7a3-4edf-84c4-794b70b6a56c
46 0022 d3d64358-964c-455f-8abc-4984b72c46c5
47 0022 8dfd9f20-382f-4401-9871-3afa06fdbeb6
48 0023 913d7735-d148-4632-9c62-5c7ca2b0e473
49 0024 2fe51a24-8613-418d-b36f-f91565045499
50 0024 7170ed39-776b-4726-9f9f-3c4da505e8de
51 0025 7f1d035d-b4b9-4d64-8f34-98fb4acc43d3
52 Testing 5d6bb22e-ee8a-4f02-9b31-33811c84e4f1
53 test d277d824-1bb1-4f3b-bb25-d768341ab23b
54 111 dbb30aab-23a0-401c-bc1c-a95537c77207
Ok. So all the sites that are marked “Team site” will be your sites in Teams or sites that were created using the teams template by going to SharePoint (in the top bar) and then select the Team template rather than the Communication template. The sites marked “Team site (classic experience)” are sites that were created before the modern experience came in. If you want to modify sites of a certain template, then yo could use Get-PNPProvisioningTemplate to get a template from a site and Apply-PnPProvisioningTemplate to apply a template to another site. So If you have a site where you added a custom list, you could get a template and apply that to another site collection.
Have you looked at the new PowerShell for MS-TEAMS ??
https://blogs.technet.microsoft.com/skypehybridguy/2017/11/07/microsoft-teams-powershell-support/
Hi Chris,
Yes, I have
https://veenstra.me.uk/2017/11/06/microsoft-teams-powershell-a-complete-getting-started-guide/
It was a bit disappointing though.
Instead of reading the entries from the hidden list, you can also enter:
Get-PnPTenantSite -WebTemplate GROUP#0
which will show all your modern team sites.
Thanks Erwin!
I think when I tried that in the past (without the -WebTemplate Group#0) I didn’t get the full list of sites back. With the WebTemplate option it indeed works. I’m not sure that I like it that the Get-PnPTenantSite doesn’t return all the sites which use the Group#0 template though.
“So now we need to find a way to filter out the Modern Team sites that were created within SharePoint rather than Microsoft Teams” – do we have a way of listing all of the sites created by Microsoft Teams yet ? Or does Erwin’s PnP PowerShell resolve the issue ?
Hi Nigel,
In the below conversation Tony Redmond is suggesting a few options:
https://techcommunity.microsoft.com/t5/Microsoft-Teams/view-a-list-of-all-Teams-that-have-been-created-in-Microsoft/m-p/65067