0

Trying to import a csv file with list of users and export a csv file with these users + the groups they are member of..

I tried the script from this Topic: Import list of users - Export List of users and Groups

But it didn't work.

Example of my user list file (test_alex.csv):

Name                                                                                                                                                                                                 
----                                                                                                                                                                                                 
Alex Alex
Test Test
You Me

That's the error i get:

Get-AdUser : The search filter cannot be recognized At line:2 char:29 + ForEach-Object -pv user { Get-AdUser -filter "displayname -eq '$($_.username)' ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-ADUser], ADException + FullyQualifiedErrorId : ActiveDirectoryServer:8254,Microsoft.ActiveDirectory.Management.Commands.GetADUser
hightest
  • 395
  • 5
  • 15
  • 1
    Please add more details about what didn't work, what did you expect? What happens instead? (see [How to Ask](https://stackoverflow.com/help/how-to-ask)) – iRon Mar 18 '20 at 17:05
  • You tried the script at the URL you posted, what was the error you got? Can you post your version of the code so that we can begin to troubleshoot? – shadow2020 Mar 18 '20 at 19:22
  • put the error into in your post above. also "-eq" is for numbers... try `-match` instead. – shadow2020 Mar 18 '20 at 22:19
  • @shadow2020 changed to -match and getting this error "Error parsing query: 'displayname -match" – hightest Mar 19 '20 at 09:12

1 Answers1

0

Maybe not the best solution from a powershell expert, but it do exactly what i was needed.

First Download this script: https://gallery.technet.microsoft.com/PowerShell-Get-All-Group-167a9ce7#content

Then open powershell ISE and use this script with the the script you downloaded.

My File name: userlist.csv

$user = "userlist.csv"
$content = Get-Content $user
$content | Foreach {$_.TrimEnd()} | Set-Content $user
C:\temp\TheActualScripts\Multiple_UserGroup_InputFile.ps1 -CSVFile "C:\temp\copy\$user"
Rename-Item -Path "C:\temp\TheActualScripts\ReportFile.txt" -NewName "$user"

Then you will get the output file named "ReportFile.txt" inside the folder where is the script located, for me it was: C:\temp\TheActualScripts\ReportFile.txt

The last line of the script change the name of the file "ReportFile.txt" to the name of the "userlist" file.

IMPORTANT

Pay attention that there is no blank spaces inside the users files that you are working with them, because if there are, the script won't work, it will just give you an empty "ReportFile.txt" file.

hightest
  • 395
  • 5
  • 15