Parsing array to New-ADGroup RRS feed

  • Question

  • Hello all, 

    I would like to know, where is an issue with my commands. I'm trying to export AD groups name to txt file and import create same groups on another server. I know that there is another way how to do it(via export-csv), but I would like to know why it is not working.

    Server1 - get names of ad groups

    Get-AdGroup -SearchBase "ou=test,dc=contoso,dc=com" -filter * | select Name | Out-File C:\groups.txt

    Server2 - read file, create groups

    $groups= Get-Contect ./groups.txt

    foreach ($i in $groups) {New-ADGroup -Name $i -GroupScope DomainLocal -GroupCategory Security -path "xxx" }

    There are only names of groups in the file. It is because of the way how I read the array, but I dont know why. Isnt $i string type?

    Thank you

    Thursday, July 13, 2017 6:34 PM


  • Start with:

    Get-AdGroup -SearchBase "ou=test,dc=contoso,dc=com" -filter * | select -Expand Name | Out-File C:\groups.txt


    • Marked as answer by Tomas Cinki Friday, July 14, 2017 6:51 AM
    Thursday, July 13, 2017 6:52 PM