BRONZE PARTNER:
BRONZE PARTNER:
Industry News:

| |
| |
 |
 |
 |
 |
 |
| There is always a better way: PowerShell export-csv cmdlet |
 |
|
|
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!
|
 |
 |
 |
|
|