Jack
Jack

Reputation: 321

How to load Powershell result into CSV or text file?

I'm trying to load powershell result into a CSV or text file

First I need to get all disabled account using this:

Search-ADAccount -AccountDisabled -UsersOnly |FT Name

And it will return bunch of names that has been disabled. What should I do to load it into a CSV or TXT file?

Here is what I tried:

Search-ADAccount -AccountDisabled -UsersOnly |FT Name | Export-CSV -Path C:\Users\hou\Downloads\Test.csv

But the result is a bunch of things like '27c87ef9bbda4f709f6b4002fa4af63c', not the name that I want to.

What should I do to do this?

Upvotes: 0

Views: 2269

Answers (1)

jimhark
jimhark

Reputation: 5046

Maybe:

Search-ADAccount -AccountDisabled -UsersOnly | 
    Select Name | 
    Export-CSV -Path C:\Users\hou\Downloads\Test.csv -NoTypeInformation

Then you'll have a CSV file with just the Names (including a header), that you can use as input to your DB's CSV import.

Format-Table transforms the objects into a stream of Formatting records which are intended for output but not for further processing. If you want to learn more about this see:

PowerShell Basics: Formatting

How PowerShell Formatting and Outputting REALLY works

Upvotes: 2

Related Questions