How to add email to Security group

Hi all,

I’m trying to create a script that i can create security group but i cannot find a way to add email adress
this my scrip:

$Name = Read-Host -Prompt "Enter DL name"
$DisplayName = $Name
$Securitypath = "OU=Groups,OU=Alex,DC=alex,DC=local"

New-ADGroup -Name $Name -DisplayName $DisplayName -GroupCategory Security  -GroupScope Universal  -Path $Securitypath -SamAccountName $Name -Description "Test Group" -ManagedBy vinokura
Write-Host -ForegroundColor Green "The group "$Name" created successfully."

anyone can help?

Thank you

I’m not sure if you can create a mail enabled security group without using the Exchange cmdlets. However, if you can, then as with users, OtherAttributes should be passed as a hashtable.

New-ADGroup -Name $Name -DisplayName $DisplayName -GroupCategory Security  -GroupScope Universal  -Path $Securitypath -SamAccountName $Name -Description "Test Group" -ManagedBy vinokura -OtherAttributes @{ 'mail' = 'my.group@contoso.com' }

For better readability, you should consider splatting:

$groupParameters    = @{
    Name            = $Name
    DisplayName     = $DisplayName
    GroupCategory   = 'Security'
    GroupScope      = 'Universal'
    Path            = $Securitypath
    sAMAccountName  = $Name
    Description     = 'Test Group'
    ManagedBy       = 'vinokura'
    OtherAttributes = @{ 
        'mail' = 'my.group@contoso.com' 
    }
}


New-ADGroup @groupParameters

Thank you
i found a way to that