M365: O365 Groups – PowerShell script to verify whether guest access is enable or disabled

Hi All,

LIFE IS BEAUTIFUL 🙂 Today with O365 groups 🙂

Background: We have O365 applications where users orders Teams. We have custom form for ordering the Teams. On custom form there is classification selection either Internal or External as shown in below figure:

Custom Teams creation App - "External classification" field based on this External sharing will be enabled or disabled
Fig1: M365 : Custom Teams creation App – “External classification” field based on this External sharing will be enabled or disabled

So here, if Team owner has selected classification as “External” then we are enabling guest access on respective O365 group otherwise disabling the guest access.

So we have implementation done and we are testing but any how we noticed that guest access settings are not working. So we need to check whether really guest access which we are updating through our CSOM job is working or now.

To verify guest access is really working for Office 365 group or not, we have only one option PowerShell script. So here is the article, I am sharing this small PowerShell script.

AllowToAddGuests” property is used to update the “Guest Access” for O365 group. This means ability to add guest to O365 group owners.

Detailed Steps:

  • Import “AzureADPreview” module
Import-Module AzureADPreview
  • Connect to AzureAD
AzureADPreview\Connect-AzureAD
  • Get the group ID
$groupID= (Get-AzureADGroup -SearchString "<Group name>").ObjectId
  • Get the group settings
Get-AzureADObjectSetting -TargetObjectId $groupID -TargetType Groups | fl Values

Complete PowerShell script:

Import-Module AzureADPreview
AzureADPreview\Connect-AzureAD
$groupID= (Get-AzureADGroup -SearchString "<Group name>").ObjectId
Get-AzureADObjectSetting -TargetObjectId $groupID -TargetType Groups | fl Values

When we will execute the above commands, it will prompt for User Name and Passwords as

M365 : O365 Group - Connecting to Azure AD - Prompt for User Name
Fig2: M365 : O365 Group – Connecting to Azure AD – Prompt for User Name
M365 : O365 Group - Connecting to Azure AD - Prompt for Password
Fig3: M365 : O365 Group – Connecting to Azure AD – Prompt for Password
M365 : Verifying guest access for O365 group and Script
Fig4: M365 : Verifying guest access for O365 group and Script

In separate article I’ll share another PowerShell script – How to enable / disable guest access to the O365 group.

References:

Enjoy the LIFE journey 🙂 Feel free to connect us, Feedback / Suggestions / Comments are welcome 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL :) ENJOY THE WHOLE JOURNEY :) Founder of Knowledge Junction and live-beautiful-life.com, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

You may also like...

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

%d bloggers like this: