Hi,
why are you filtering the properties in that way?
Why not doing a simpler thing like:
How to Get a List of All Users from a Specific OU
Regards,
Stoyan
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Good afternoon,
I have to export the list of users contained in an OU to a csv file, the code I wrote is the following:
Get-ADUser -Filter * -SearchBase "OU = XX, OU = YY, DC = mydomain, DC = local" -Properties DisplayName | Select-Object -Property @ {Name = "Name"; Expression = {$ _. Displayname}}, @ {Name = "Account"; Expression = {$ _. Samaccountname}} | Sort-Object Name | Export-Csv -Path c: \ temp \ list.csv
So account name and username are all written in one cell, I would like them to be written in two separate cells, one called "account name" and one "username".
Thank you.
Hi,
why are you filtering the properties in that way?
Why not doing a simpler thing like:
How to Get a List of All Users from a Specific OU
Regards,
Stoyan
Unless I've completely misunderstood your code, that should not happen. You're selecting two different properties (which will create a PSCustomObject) and passing the date into a sort and then exporting the object to a CSV.
First, add the "-NoTypeInformation" switch to your Export-CSV (to eliminate any clutter in the file). Then rerun your code. If you import the CSV into Excel you should see two columns. If you use PowerShell's Import-CSV and examine each row you should see two properties.
If you'd like (for testing), add "-First 3" to your Select-Object and remove the Export-CSV. You should see three users in a tabular format with the two properties you named in the Select-Object.
If that's not what you're seeing, post the first three lines of your exported CSV and the code you ran to produce it so we can see what you're experiencing.
Hi,
I ran the script and the two properties were seperated in Excel. You could open the csv file with notepad and the two properties should be seperated by comma like "Name","Account"
You could also add "-Delimiter" to Export-Csv to try another delimiter like -Delimiter "|"
Best Regards,
Ian
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Thanks everyone for your answers.
Stoyan actually your solution is much simpler, I'll start thinking less complicated.
Rich, Ian, I followed your suggestions but the problem still presented itself. I imported the csv to Excel on another pc and the output was the desired one, so the problem was on Excel which restored it started to display the output correctly.
Thanks again for your suggestions.
Roberto.