Microsoft 365 : Microsoft Graph PowerShell tutorial – Part 6 – exploring Get-MgSite

Hi All,
Greetings for the day!
Continuing on my favorite topic – Microsoft Graph Powershell.
Today we will discussing one of the important CMDLET – Get-MgSite
Get-MGSite
- This CMDLET is required to get particular site details
- This CMDLET is part of module – Microsoft.Graph.Sites
- Permissions (delegated permissions) required to execute – Get-MgSite
- Sites.Read.ALL
- SYNTAX
Get-MgSite
[-ExpandProperty <String[]>]
[-Property <String[]>]
[-Filter <String>]
[-Search <String>]
[-Skip <Int32>]
[-Sort <String[]>]
[-Top <Int32>]
[-PageSize <Int32>]
[-All]
[-CountVariable <String>]
[<CommonParameters>]
Get-MgSite
-SiteId <String>
[-ExpandProperty <String[]>]
[-Property <String[]>]
[<CommonParameters>]
Executing the CMDLET – Connecting to Microsoft Graph using Connect-MgGraph
- As discussed in one of the article – Microsoft 365 : PowerShell – Microsoft Graph PowerShell tutorial – Part 1 – https://knowledge-junction.in/2023/08/30/microsoft-365-powershell-microsoft-graph-powershell-tutorial-part-1/, we need to invoke – Connect-MgGraph before executing any Microsoft Graph PowerShell CMDLET.
- This CMDLET (Connect-MgGraph) get access token using Microsoft Authentication Library
- Here we will use delegated access permission and interactive authentication as in below snap. We are executing the CMDLET from Windows PowerShell ISE
Connect-MgGraph -Scopes "Sites.Read.All"
- Here scope parameter specifies – An array of delegated permissions to consent to.
- When we execute this CMDLET we get prompt for credentials
- As we connected the Microsoft Graph successfully, we are ready to execute OUR CMDLETs

Examples – Get-MgSite
- Example 1 – Search all sites with keyword – Demo
Get-MgSite -search demo
Output:
Id DisplayName Name
-- ----------- ----
knowledgejunction1.sharepoint.com,78aaa1ac-73f6-494c-8596-53cb5251fec1,f7b914d6-a4dc-4819-9eaa-bd3629621aa7 Demo Demo
knowledgejunction1.sharepoint.com,1a22eb80-09e2-44eb-a8a3-124fdb294b48,851fecab-3fc8-4b9d-add8-91866cabb2f4 Demo Remove User Permissions demoremoveuserpermissions
knowledgejunction1.sharepoint.com,5e4679c7-8646-4380-bf33-9ecac5769e8d,80dc1529-dc01-4c97-a421-bc61127d72aa Blogs Demo BlogsDemo
knowledgejunction1.sharepoint.com,c7117a91-c034-43e8-b335-5b5418a39d44,f7b914d6-a4dc-4819-9eaa-bd3629621aa7 SharePoint App Bar Demo SharePointAppBarDemo
knowledgejunction1.sharepoint.com,59e1907a-bd11-4f00-af1b-b2ab19f24dac,5de3c42f-bee2-4a67-a1fa-b034bc9da1c0 App Installation On Subsite Demo appinstallation
knowledgejunction1.sharepoint.com,faaf70ba-780e-4f8e-a3ec-c7f632ab4691,f5d8fc1b-fca4-4325-8740-bc38100be195 SPS_Demo_SiteLifeCycle_24.03.20 sps_demo_sitelifecycle_24...
knowledgejunction1.sharepoint.com,237c32a1-0683-4fbf-ae85-d0231608241e,5aa56e36-22be-4f34-8093-650b39c2be27 spswapdemo knowledgejunction1.sharep...
knowledgejunction1.sharepoint.com,78aaa1ac-73f6-494c-8596-53cb5251fec1,316d488f-d1a3-4e97-a4fa-d896f1e68900 DemoPermissions PermissionsDemo
knowledgejunction1.sharepoint.com,3d53cd5b-5064-4665-ac14-f512b6636b60,0dd4435c-8a5e-449e-b3a4-b80a84bd60eb SPGovernance SPGovernance
knowledgejunction1.sharepoint.com,78aaa1ac-73f6-494c-8596-53cb5251fec1,748faf55-e7cc-4a9d-a258-5a865c3d2f4f DemoSpaceInURL Space In URL

- Example 2 – Get specific site with site ID – Demo
- Here if we dont know specific site ID – we could form it – <domain>.sharepoint.com/sites/<sitename> – as in below snap
#Example 2 - Get specific site details with "siteid" parameter - kindly please note the value for #siteid parameter
Get-MgSite -siteid "knowledgejunction1.sharepoint.com:/sites/demo" |fl
Output:
PS C:\> Get-MgSite -siteid "knowledgejunction1.sharepoint.com:/sites/demo"
Id DisplayName Name WebUrl
-- ----------- ---- ------
knowledgejunction1.sharepoint.com,78aaa1ac-73f6-494c-8596-53cb5251fec1,f7b914d6-a4dc-4819-9eaa-bd3629621aa7 Demo Demo https://knowledgejunction1.sharepoint.com...
PS C:\> Get-MgSite -siteid "knowledgejunction1.sharepoint.com:/sites/demo" |fl
Analytics : Microsoft.Graph.PowerShell.Models.MicrosoftGraphItemAnalytics1
Columns :
ContentTypes :
CreatedBy : Microsoft.Graph.PowerShell.Models.MicrosoftGraphIdentitySet
CreatedByUser : Microsoft.Graph.PowerShell.Models.MicrosoftGraphUser
CreatedDateTime : 8/3/2022 12:06:18 PM
Description :
DisplayName : Demo
Drive : Microsoft.Graph.PowerShell.Models.MicrosoftGraphDrive
Drives :
ETag :
Error : Microsoft.Graph.PowerShell.Models.MicrosoftGraphPublicError
ExternalColumns :
Id : knowledgejunction1.sharepoint.com,78aaa1ac-73f6-494c-8596-53cb5251fec1,f7b914d6-a4dc-4819-9eaa-bd3629621aa7
Items :
LastModifiedBy : Microsoft.Graph.PowerShell.Models.MicrosoftGraphIdentitySet
LastModifiedByUser : Microsoft.Graph.PowerShell.Models.MicrosoftGraphUser
LastModifiedDateTime : 1/29/2024 6:02:01 AM
Lists :
Name : Demo
Onenote : Microsoft.Graph.PowerShell.Models.MicrosoftGraphOnenote1
Operations :
ParentReference : Microsoft.Graph.PowerShell.Models.MicrosoftGraphItemReference
Permissions :
Root : Microsoft.Graph.PowerShell.Models.MicrosoftGraphRoot
SharepointIds : Microsoft.Graph.PowerShell.Models.MicrosoftGraphSharepointIds
SiteCollection : Microsoft.Graph.PowerShell.Models.MicrosoftGraphSiteCollection
Sites :
TermStore : Microsoft.Graph.PowerShell.Models.MicrosoftGraphTermStore1
TermStores :
WebUrl : https://knowledgejunction1.sharepoint.com/sites/Demo
AdditionalProperties : {[@odata.context, https://graph.microsoft.com/v1.0/$metadata#sites/$entity]}

Example 3 – Get specific site with site ID with specific properties
- By default, Get-MgSite returns – Id, Name, DisplayName and URL properties
- To get additional required properties we need to specify those properties explicitly with –Property attribute as in below snap / code
#Example 3 - Get specific site details with "siteid" parameter and with selected properties- kindly please note the value for siteid parameter
$site = Get-MgSite -siteid "knowledgejunction1.sharepoint.com:/sites/demo" -Property "CreatedDateTime, LastModifiedDateTime"
"Site created on - " + $site.CreatedDateTime
"Site last modified on - " + $site.LastModifiedDateTime
Output:
Site created on - 08/03/2022 12:06:18
Site last modified on - 01/29/2024 16:40:43

Microsoft Graph APIs are way to go now for Microsoft 365. We have very good series of articles on Microsoft Graph. Kindly please have a look – https://knowledge-junction.in/?s=microsoft+graph OR https://knowledge-junction.in/category/technology-articles/m365/microsoft-graph/
REFERENCES
- Microsoft 365 : PowerShell – Microsoft Graph PowerShell tutorial – Part 1 – https://knowledge-junction.in/2023/08/30/microsoft-365-powershell-microsoft-graph-powershell-tutorial-part-1/
- Microsoft Graph APIs tutorial – https://knowledge-junction.in/?s=microsoft+graph OR https://knowledge-junction.in/category/technology-articles/m365/microsoft-graph/
- Introductory article for Microsoft Graph PowerShell – Microsoft 365 – Microsoft Graph PowerShell – way to go now – https://knowledge-junction.in/2024/01/25/microsoft-365-microsoft-graph-powershell-way-to-go-now/
- In part 1 of the series we discussed – how to start with Microsoft Graph PowerShell. If you did not got chance to look, kindly please have a look – Microsoft 365 : PowerShell – Microsoft Graph PowerShell tutorial – Part 1 – https://knowledge-junction.in/2023/08/30/microsoft-365-powershell-microsoft-graph-powershell-tutorial-part-1/
- In part 2 of the series we explored CMDLET – Connect-MgGraph – Microsoft 365 : PowerShell – Microsoft Graph PowerShell tutorial – Part 2 – exploring Connect-MgGraph with couple of scenarios – https://knowledge-junction.in/2024/01/18/microsoft-365-powershell-microsoft-graph-powershell-tutorial-part-2-exploring-connect-mggraph-with-couple-of-scenarios/
- In part 3 of the series we explored CMDLET – Connect-MgGraph – Microsoft 365 : Microsoft Graph PowerShell tutorial – Part 3 – using client id (App ID) and certificate for connecting graph – Connect-MgGraph – https://knowledge-junction.in/2024/01/21/m365-msgraph-powershell-tutorial-part-3-using-client-id-app-id-n-certificate-connecting-graph/
- In part 4 of the series we are implementing Governance – Fetching all Global Administrators in tenant – Microsoft 365 : Microsoft Graph PowerShell tutorial – Part 4 – Implementing Governance – Fetching all Global Administrators in tenant – https://knowledge-junction.in/2024/01/23/microsoft-365-microsoft-graph-powershell-tutorial-part-4/
- In 5th part of series we are discussing one of the important Microsoft Graph PowerShell CMDLET – Find-MgGraphCpmmand Microsoft 365 : Microsoft Graph PowerShell tutorial – Part 5 – exploring Find-MgGraphCommand – https://knowledge-junction.in/2024/01/27/ms365mgpowershellfind-mggraphcommand/
- In this article we are describing integration of Microsoft Graph with .NET Core – Navigating the Cloud: Harnessing the Power of Microsoft Graph APIs in .NET Core Applications – https://knowledge-junction.in/2024/01/27/navigating-the-cloud-harnessing-the-power-of-microsoft-graph-apis-in-net-core-applications/
Thanks for reading ! Stay tuned for more articles on PowerShell and Microsoft Graph !
HAPPY LEARNING AHEAD 🙂 LIFE IS BEAUTIFUL 🙂

You must be logged in to post a comment.