We help IT Professionals succeed at work.

putting into a basic Powershell script to create CSV output

I am still a beginner with Powershell and have a DSQUERY command I want output to CSV, Can you help me in the right direction? Thank you!


dsquery * "OU=Domain Controllers,DC=Contoso,DC=Com" -filter "(&(objectCategory=computer)(operatingSystem=*2003*))"

Open in new window

Comment
Watch Question

Top Expert 2013
Commented:
did you try to output it to a csv   (at the end > file.csv)

One other cool method is adfind that lets you use csv format and is very similar to your command

http://www.joeware.net/freetools/tools/adfind/index.htm

adfind -default -b "OU=Domain Controllers,DC=Contoso,DC=Com" -f "&(objectCategory=computer)(operatingSystem=*2003*)"  name operatingsystemversion  -csv > Windows2003.csv

Thanks

Mike

Author

Commented:
I was hoping to see it in action in Powershell! The redirecting I have done before and I have used joeware in the past. Both good options, but I am trying to be a bit more modern with my Powershell usage. Thank you!

Author

Commented:
On this website I found 4 ways to write to file...

http://blogs.technet.com/b/gbordier/archive/2009/05/05/powershell-and-writing-files-how-fast-can-you-write-to-a-file.aspx

I will use StreamWriter since the output may be large.

Author

Commented:
Thank you!