export AD groups

Rising Flight 3,711 Reputation points
2021-09-07T20:34:02.677+00:00

Hi All

i have a csv file and it has 600 AD groups mentioned in it in the below format, the csv file is not in proper format. only the first 3 characters(100, 111,112,120) are correct. is it possible to get the exact AD group names by importing the csv using the first 3 characters. i want the samaccount names and description of the AD groups, is it possible to fetch this information. please guide me

groups
100-abc
111xyz
112-uiy
120_poi

Windows Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,441 questions
Windows Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,367 questions
Windows Server 2012
Windows Server 2012
A Microsoft server operating system that supports enterprise-level management, data storage, applications, and communications.
1,525 questions
Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
5,814 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,352 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 44,621 Reputation points
    2021-09-08T01:39:42.08+00:00

    If the groups names "100", "111", "112", "120" then you can do it pretty easily.

    Maybe something like this:

    Import-CSV -c:\junk\groups.csv |
        ForEach-Object{
            $groupname = ($_.groups).substring(0,3)
            Get-ADGroup -Filter "name -eq $groupname" |         # you may need to add a -Properties list; or change "-eq" to "-like"
                Select-Object Name, ssmAccountName, Description
        } | Export-CSV c:\junk\group-extract.csv -NoTypeInformation
    
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Rising Flight 3,711 Reputation points
    2021-09-08T04:19:20.95+00:00

    i tried the above syntax i am getting blank output


  2. Limitless Technology 39,336 Reputation points
    2021-09-08T10:54:07.683+00:00

    Hello,

    In theory, for pulling out groups you can use Get-ADGroup:

    Get-ADGroup -Filter {name -like "100-abc*"} -Properties Description | Select Name,Description

    Then loop through the results (either CSV or directly off of the command above) and use Set-ADGroup to make your changes.

    Help Set-ADGroup -Full

    Regards,