Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with Script - Prevent guests from being added to a specific Microsoft 365 group or Microsoft Teams team #2655

Closed
sachiin123 opened this issue Mar 28, 2024 · 2 comments

Comments

@sachiin123
Copy link

Thanks for reporting the bug. Please ensure you've gone through the following checklist before opening an issue:

Describe the bug
** Prevent guests from being added to a specific group | Microsoft Learn
Prevent guests from being added to a specific group
Learn how to prevent guests from being added to a specific group

In this script, Once I run this script and when I going to run script second time to revert changes - I am getting below error - attached.
Image

I tested this in two different tenant and same error***

Script-
Connect-MgGraph

$GroupName = ""
$templateId = (Get-MgBetaDirectorySettingTemplate | ? {$_.displayname -eq "group.unified.guest"}).Id
$groupID = (Get-MgBetaGroup -Filter "DisplayName eq '$GroupName'").Id

$params = @{
templateId = "$templateId"
values = @(
@{
name = "AllowToAddGuests"
value = "true"
}
)
}

New-MgBetaGroupSetting -GroupId $groupID -BodyParameter $params

Module Version

Please run Get-Module Microsoft.Graph* after cmdlet execution and paste the output below.
If a module cannot be installed or imported, please run Get-Module -ListAvailable and paste the output.
ModuleType Version Name ExportedCommands


Script 1.0.0.0 ISE {Get-IseSnippet, Import-IseSnippet, New-IseSnippet}
Script 2.15.0 Microsoft.Graph.Authentication {Add-MgEnvironment, Connect-MgGraph, Disconnect-MgGraph, Get-MgContext...}
Script 2.15.0 Microsoft.Graph.Beta.Groups {Add-MgBetaGroupDriveListContentTypeCopy, Add-MgBetaGroupDriveListContentTypeCopyFromContentTypeHub, Add-MgBeta...
Script 2.15.0 Microsoft.Graph.Beta.Identity.Di... {Add-MgBetaTenantRelationshipManagedTenantAlertUserInputLog, Add-MgBetaTenantRelationshipManagedTenantManagemen...
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
Manifest 3.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature...}
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Script 4.9.1 MicrosoftTeams {Add-TeamChannelUser, Add-TeamUser, Connect-MicrosoftTeams, Disconnect-MicrosoftTeams...}

Environment Data

Please run $PSVersionTable and paste the output below. If running the Docker container image, indicate the tag of the image used and the version of Docker engine.
Name Value


PSVersion 5.1.22000.2713
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.22000.2713
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Screenshots

If applicable, add screenshots to help explain your problem.
Image

@SeniorConsulting
Copy link

Gidday,

I can see you've been following the guide from the link you've provided. Normally cmdlets with New-Mgxxxxx are things that are creating new things (new users, new groups etc). So running that command twice would try to create two different sets of settings against the same group (which is why you're getting the error you are). So, given that you've already created the setting to set it to false, and have indicated that you're trying to toggle back, have you tried using: Update-MgBetaGroupSetting instead of New-MgBetaGroupSetting?

Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants