Creating groups
Create a global security group
- ADSI
-
Import-Module Adaxes # Connect to the Adaxes service $ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace" $service = $ns.GetServiceDirectly("localhost") # Bind to the target container $containerDN = "CN=Groups,DC=domain,DC=com" $container = $service.OpenObject("Adaxes://$containerDN", ` $null, $null, 0) # Create group [Softerra.Adaxes.Interop.Adsi.ADS_GROUP_TYPE_ENUM]$groupType = "ADS_GROUP_TYPE_GLOBAL_GROUP, ADS_GROUP_TYPE_SECURITY_ENABLED" $group = $container.Create("group","CN=New Group") $group.Put("groupType", [int]$groupType) $group.SetInfo() - PowerShell
-
Import-Module Adaxes $containerDN = "CN=Groups,DC=domain,DC=com" New-AdmGroup -Name "New Group" -Path $containerDN ` -GroupCategory Security -GroupScope Global ` -Server "domain.com" -AdaxesService localhost
The following code sample creates a global security group and includes a reason for creating it.
Import-Module Adaxes
# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")
# Bind to the target container
$containerDN = "CN=Groups,DC=domain,DC=com"
$container = $service.OpenObject("Adaxes://$containerDN", `
$null, $null, 0)
# Create group
[Softerra.Adaxes.Interop.Adsi.ADS_GROUP_TYPE_ENUM]$groupType =
"ADS_GROUP_TYPE_GLOBAL_GROUP, ADS_GROUP_TYPE_SECURITY_ENABLED"
$group = $container.Create("group","CN=New Group")
$group.Put("groupType", [int]$groupType)
# Specify reason for creation
$group.SetReason($reason)
$reason = [Softerra.Adaxes.Adsi.OperationReasonInfo]::new(
"#1234", # Reason
"Ticket number" # Field label
)
# Commit changes to the directory
$group.SetInfo()
Create a local distribution group
- ADSI
-
Import-Module Adaxes # Connect to the Adaxes service $ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace" $service = $ns.GetServiceDirectly("localhost") # Bind to the target container $containerDN = "CN=Groups,DC=domain,DC=com" $container = $service.OpenObject("Adaxes://$containerDN", ` $null, $null, 0) # Create group [Softerra.Adaxes.Interop.Adsi.ADS_GROUP_TYPE_ENUM]$groupType = "ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP" $group = $container.Create("group","CN=New Group") $group.Put("groupType", [int]$groupType) $group.SetInfo() - PowerShell
-
Import-Module Adaxes $containerDN = "CN=Groups,DC=domain,DC=com" New-AdmGroup -Name "New Group" -Path $containerDN ` -GroupCategory Distribution -GroupScope DomainLocal ` -Server "domain.com" -AdaxesService localhost
Create a Microsoft 365 group
- ADSI
-
Import-Module Adaxes # Connect to the Adaxes service $ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace" $service = $ns.GetServiceDirectly("localhost") # Bind to the target container $containerDN = "OU=Groups,DC=domain,DC=onmicrosoft,DC=com" $container = $service.OpenObject("Adaxes://$containerDN", ` $null, $null, 0) # Create group [Softerra.Adaxes.Interop.Adsi.AzureADGroupType]$groupType = "Microsoft365" $group = $container.Create("group","CN=New Group") $group.Put("adm-AzureGroupType", [int]$groupType) $group.SetInfo() - PowerShell
-
Import-Module Adaxes $containerDN = "OU=Groups,DC=domain,DC=onmicrosoft,DC=com" New-AdmGroup -Name "New Group" -Path $containerDN ` -GroupCategory Microsoft365 ` -Server "domain.com" -AdaxesService localhost
See also
- Writing ADSI scripts
- Server-side scripting
- IADs
- IADsContainer
- IADsGroup
- INextOperationReason
- New-AdmGroup
- Online script repository