question

RisingFlight-7863 avatar image
0 Votes"
RisingFlight-7863 asked RichMatheisen-8856 commented

export AD groups

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-powershellwindows-active-directorywindows-server-2019windows-server-2016windows-server-2012
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered RichMatheisen-8856 edited

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RisingFlight-7863 avatar image
0 Votes"
RisingFlight-7863 answered RichMatheisen-8856 commented

i tried the above syntax i am getting blank output

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Sorry! Line #3 was missing the letter "s" at the end if the word "group". I've fixed the code sample.

0 Votes 0 ·
LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered RichMatheisen-8856 commented

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,

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You really should try reading the entire question!

Here. I'll quote the relevant parts for you:

only the first 3 characters(100, 111,112,120) are correct.

and:

using the first 3 characters



0 Votes 0 ·