-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patho365-prevent-users-from-creating-groups.ps1
34 lines (28 loc) · 1.44 KB
/
o365-prevent-users-from-creating-groups.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<#
.Description
This script prevents standard users in the o365 tenancy from creating groups. Only members of group "Group Creators" can
create groups. Obviously, the group name may be adjusted as needed, but needs to match whatever is setup in AzureAD.
Requires "Install-Module AzureADPreview". If AzureAD module is already installed, uninstall it first
using "Uninstall-Module AzureAD" or else you'll get a long, nonsencical error.
#>
$GroupName = "Group Creators"
$AllowGroupCreation = $False
Connect-AzureAD
$settingsObjectID = (Get-AzureADDirectorySetting | Where-object -Property Displayname -Value "Group.Unified" -EQ).id
if(!$settingsObjectID)
{
$template = Get-AzureADDirectorySettingTemplate | Where-object {$_.displayname -eq "group.unified"}
$settingsCopy = $template.CreateDirectorySetting()
New-AzureADDirectorySetting -DirectorySetting $settingsCopy
$settingsObjectID = (Get-AzureADDirectorySetting | Where-object -Property Displayname -Value "Group.Unified" -EQ).id
}
$settingsCopy = Get-AzureADDirectorySetting -Id $settingsObjectID
$settingsCopy["EnableGroupCreation"] = $AllowGroupCreation
if($GroupName)
{
$settingsCopy["GroupCreationAllowedGroupId"] = (Get-AzureADGroup -SearchString $GroupName).objectid
} else {
$settingsCopy["GroupCreationAllowedGroupId"] = $GroupName
}
Set-AzureADDirectorySetting -Id $settingsObjectID -DirectorySetting $settingsCopy
(Get-AzureADDirectorySetting -Id $settingsObjectID).Values