Hi<\/p>\n
I need help in exporting members of DL.<\/p>\n
The script should read the DL’s from a CSV file and export the users ( domain login name and full name) to file. One file should be created for each DL with DL name.That means if the CSV file has 10 DL names, then the script should create 10 individual files with the DL name<\/p>","upvoteCount":6,"answerCount":25,"datePublished":"2021-06-16T07:48:06.000Z","author":{"@type":"Person","name":"rapartykish1863","url":"https://community.spiceworks.com/u/rapartykish1863"},"acceptedAnswer":{"@type":"Answer","text":"
$Groups = Import-CSV -Path \".\\Groups.csv\"\n\nforeach($group in $groups)\n{\n Get-ADGroupMember -Identity $group.Name -Recursive\n\n Start-Sleep 1\n\n Get-ADGroupMember -Identity $group.Name -Recursive | Select-Object SAMAccountName, name | Sort-Object SAMAccountName\n\n #Get-ScreenShot -Path $path\n\n $membership = Get-ADGroupMember -Identity $group.Name -Recursive | Select-Object SAMAccountName, name | Sort-Object SAMAccountName\n\n $membershipString = \"Username | Name`n\"\n foreach($user in $membership)\n {\n $membershipString += \"{0} | {1}`n\" -f $user.SAMAccountName, $user.name\n }\n \n# $description = @()\n# @description += \"Group Name:=\" + $group.Name.ToString() + \"Membership=\" + $membershipString\n<\/code><\/pre>\nWorks apart from the last two lines. What are you trying to acheive with them?<\/p>","upvoteCount":1,"datePublished":"2021-06-16T11:28:33.000Z","url":"https://community.spiceworks.com/t/need-help-on-dl-export/802895/4","author":{"@type":"Person","name":"grsl","url":"https://community.spiceworks.com/u/grsl"}},"suggestedAnswer":[{"@type":"Answer","text":"
Edit: Welcome to SpiceWorks<\/p>\n
Show us the code you have so far.<\/p>","upvoteCount":1,"datePublished":"2021-06-16T09:16:58.000Z","url":"https://community.spiceworks.com/t/need-help-on-dl-export/802895/2","author":{"@type":"Person","name":"grsl","url":"https://community.spiceworks.com/u/grsl"}},{"@type":"Answer","text":"
Hi,<\/p>\n
Below is my code<\/p>\n
$Groups = Import-CSV -Path “.\\xxx.csv”<\/p>\n
foreach($group in $groups)<\/p>\n
{<\/p>\n
“Command: Get-ADGroupMember -Identity {0} -Recursive” -f $group.Name
\nStart-Sleep 1
\nGet-ADGroupMember -Identity $group.Name -Recursive | Select-Object SAMAccountName, name | Sort-Object SAMAccountName
\n#Get-ScreenShot<\/span> -Path $path<\/p>\n$membership = Get-ADGroupMember -Identity $group.Name -Recursive | Select-Object SAMAccountName, name | Sort-Object SAMAccountName<\/p>\n
$membershipString = “Username | Namen\" foreach($user in $membership) { $membershipString += \"{0} | {1}<\/code>n” -f $user.SAMAccountName, $user.name
\n}<\/p>\n$description = @\"
\nGroup Name: {0}
\n{1}
\n\"@ -f $group.Name, $membershipString
\n}<\/p>","upvoteCount":0,"datePublished":"2021-06-16T10:11:59.000Z","url":"https://community.spiceworks.com/t/need-help-on-dl-export/802895/3","author":{"@type":"Person","name":"rapartykish1863","url":"https://community.spiceworks.com/u/rapartykish1863"}},{"@type":"Answer","text":"
Hi<\/p>\n
I am trying to export the results into multiple PDFs/TXT files with DL name. For example, there are 10 DL’s in the CSV with name like DL- Test1,Dl-Test2, etc. I want the output of the members ( Name, login name) in a text file with name Dl-test1.txt<\/p>","upvoteCount":0,"datePublished":"2021-06-16T11:33:10.000Z","url":"https://community.spiceworks.com/t/need-help-on-dl-export/802895/5","author":{"@type":"Person","name":"rapartykish1863","url":"https://community.spiceworks.com/u/rapartykish1863"}},{"@type":"Answer","text":"
$Groups = Import-CSV -Path \".\\Groups.csv\"\nforeach($group in $groups) {\n Get-ADGroupMember -Identity $group.Name -Recursive\n Start-Sleep 1\n Get-ADGroupMember -Identity $group.Name -Recursive | Select-Object SAMAccountName, name | Sort-Object SAMAccountName\n #Get-ScreenShot -Path $path\n $membership = Get-ADGroupMember -Identity $group.Name -Recursive | Select-Object SAMAccountName, name | Sort-Object SAMAccountName\n $membershipString = \"Username | Name`n\"\n foreach($user in $membership) {\n $membershipString += \"{0} | {1}`n\" -f $user.SAMAccountName, $user.name\n }\n $filename = $group.Name.ToString() + \".txt\"\n New-Item -Path .\\$filename -ItemType File -Value $membershipString\n}\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2021-06-16T12:37:14.000Z","url":"https://community.spiceworks.com/t/need-help-on-dl-export/802895/6","author":{"@type":"Person","name":"grsl","url":"https://community.spiceworks.com/u/grsl"}},{"@type":"Answer","text":"Welcome.<\/p>\n
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n