Search code examples
powershellmicrosoft-graph-apimicrosoft365pnp.powershell

PowerShell - PnP - Microsoft Groups - Get Guest access setting AllowToAddGuests


I'm using the AzureADPreview module to find out if a group has guest access allowed. This is working fine and returns true/false, script shown below:

$groupSettings = Get-AzureADObjectSetting -TargetType Groups -TargetObjectId $groupId
$guestAccessEnabled = ($groupSettings["AllowToAddGuests"])
Write-Host($guestAccessEnabled)

I'm now trying to do the same but using the PnP.PowerShell module but I can't seem to get a true/false result. The following returns 'PnP.PowerShell.Commands.Model.Microsoft365GroupSettingItemValues' and I'm not sure how to expand out this object to get the 'AllowToAddGuests' setting.

$groupSettings = Get-PnPMicrosoft365GroupSettings -Identity $groupId 
Write-Host($groupSettings.Values)

I'm pretty sure this is an issue with how I'm going about accessing the object, so any help would be appreciated.


Solution

  • You can filter $groupSettings.Values and find an item with Name that equals AllowToAddGuests.

    $groupSettings = Get-PnPMicrosoft365GroupSettings -Identity $groupId 
    $allowToAddGuests = $groupSettings.Values | Where-Object {$_.Name -eq 'AllowToAddGuests'}
    Write-Host($allowToAddGuests.Value)