Grab our RSS feeds Follow us on Twitter Join our Facebook Group Connect with us on LinkedIn
myITforum.com, Powered by You.
you are not logged in

Articles

Newslinks

Links

Downloads

Site Services

Community Forums

Discussion Lists

Article Search

Newsletter

Web Blogs

FAQs

Live Support

myITforum TV

Take a Poll

Monthly Drawing

myITforum Network

User Group Directory

Our Partners

About Us

Register

Login

BRONZE PARTNER:

BRONZE PARTNER:



Industry News:




  Home : Articles : Windows PowerShell print | email | | Forums |   print | email | | Blogs |   print | email | | Wiki |   print | email | | FAQs |   print | email | Article Search  
There is always a better way: PowerShell export-csv cmdlet


Bookmark and Share

By: Ying Li
Posted On: 5/14/2008

In my previous script http://www.myitforum.com/articles/40/view.asp?id=10628

I created excel object and using PowerShell/ADSI to interact with AD and send the output to excel.

This article was Previously posted on Ying Li's Blog

At the time of that witting, I was proud of what I did - otherwise, I wouldn't publish it!

But not anymore!

I could get the similar results using the below script - one liner!

Get-QADUser -SizeLimit 0 -IncludeProperty -ip sAMAccountName, homedirectory, homedrive, Mail | Select name, sAMAccountName, HomeDirectory, HomeDrive, TsProfilePath, Mail |export-csv ADUsers.csv

Of course, in order to run the above script you need to download and install http://www.quest.com/powershell/activeroles-server.aspx from Quest.

Let me explain the above script

Get-QADUser which will retrieve all users in a domain or container that meet the specified conditions. I heard Microsoft own version of PowerShell extension is in the work and it will be something like Get-ADUser. Quest was gracious enough to leave that cmdlet to Microsoft!

-Sizelimit 0 means return all - the default will return 1000.

You have to include -IncludeProperty otherwise those properties won't show. Thanks my fellow MVP friend Demitry Sotnikov, the author of Quest PowerShell extension for the tip.

Last but not list export-csv cmdlet will export the results to an csv file which as you know is excel's poor cousin. Even though it is lacking some of the format such as Bold, autofit and colors etc. But I will still trade this one liner with my one page script!

There is always a better way!

  myITforum.com ©2010 | Legal | Privacy