How we can create a New-ADGroup with -OtherAttributes using powershell command?

1.4k Views Asked by At

New-ADGroup -Name 'mygroup1' -GroupScope 0 -OtherAttributes '@{'AttributeLDAPDisplayName'=value}'

I have tried using above command in powershell but returns following exception :

At line:1 char:45
+  New-ADGroup -Name 'mygroup1' -GroupScope 0 -OtherAttributes -Replace ...
+                                             ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [New-ADGroup], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.NewADGroup```
1

There are 1 best solutions below

0
Sridevi On

As suggested by Santiago Squarzon posting it as answer to help other community members.

If you use quotes in arguments, it will be treated as String. This is not valid for -OtherAttributes as the type of it is hashtable.

So, remove the quotes and include your values to the attribute by replacing value.

For suppose, if you are trying to create an Active Directory group based on Email address your cmdlet should be something like this:

$groupEmail = "[email protected]","[email protected]"
New-ADGroup -Name 'mygroup1' -GroupScope 0 -OtherAttributes @{'mail'=$groupEmail} -Path "CN=Users,OU=Your_OU_Name,DC=Com"

If you are trying to create AD group based on displayName, please check below cmdlet

(NOTE: You can also give the values directly like this):

 New-ADGroup -Name 'mygroup1' -GroupScope 0 -OtherAttributes @{'displayName'="Sri","Devi"} -Path "CN=Users,OU=Your_OU_Name,DC=Com"

Make sure whether you are giving correct path or not.

Please check the below references if they are helpful.

References:

https://ss64.com/ps/new-adgroup.html

https://learn.microsoft.com/en-us/powershell/module/activedirectory/new-adgroup?view=windowsserver2022-ps#parameters