Hi Guys
I am new to Powershell, so bare with me.
I have an OU with approx. 40-50 global Security Groups. These should actually have been distribution Groups instead!! Don’t ffel like changing this manually and thought I would give myself an interesting little Powershell task to Work on. But I am stuck…
I am trying to create a script to copy (not convert) these existing Security Groups to new Distribution Groups with similar names. (not covert, because we use these separately. Security Groups for shares and DL’s for mail. I read that converting COULD cause issues later on in AD).
I cannot seem to “extract” the Security Group names and create a new DL with the same name (in a different OU). I tried a ton of things collected from various Forums, but cannot make it Work. I haven’t gotten to the part where I copy members from the SG’s to the DL’s yet, but feel free to help me out with that too if possible.
Current “script”:
$name = Get-ADGroup -Filter {GroupCategory -eq ‘Security’} -SearchBase ‘OU=Test,OU=Groups,OU=DK,OU=Common Resources,DC=DOMAIN,DC=com’ | Select -Property Name | Out-String
**at this point typing: $name - outputs the correct names of the three SG’s in my test Group **
Foreach ($n in $name) {New-ADGroup -Name $_.name -GroupCategory Distribution -GroupScope Global -Path ‘OU=Test2,OU=Groups,OU=DK,OU=Common Resources,DC=DOMAIN,DC=com’}
** here I am Getting the error:
New-ADGroup : Cannot validate argument on parameter ‘Name’. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:1 char:42
- Foreach ($n in $name) {New-ADGroup -Name $_.name -GroupCategory Distribution -Gr …
-
~~~~~~~
- CategoryInfo : InvalidData: ( [New-ADGroup], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.NewADGroup
I have seen other errors for the other things I have tried, among those something regarding: Cannot convert’System.Object’ to the type ‘System.String’ Required for parameter ‘name’, which is why I added the Out-String command to the $name variable
Any help will be greatly appreciated.
Best Regards, Jesper
I