This was right on the money first try! Thanks so much for your help.
Main Topics
Browse All TopicsI use the script posted in the code section of this post to return information from Active Directory.
What I would like to know is how I can pipe the results of the $colResults variable to a csv without it giving me the LDAP and properties of the System.DirectoryServices.D
I have tried repositioning the pipe line for the Export-csv call, but it either prompts me for the input object for each machine, or else if I put it at the end, it returns an empty file with just a length header and a numeric value representing the length of the last object passed, which I assume to be a machine name.
Any idea what I'm doing wrong?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Very useful! One thing that was not clear is what the [void] on line 12 accomplishes aside from the obvious (voiding...) or why it was needed. Could you explain? I'm a bit of a PowerShell novice.
Also, could you explain the last line of code? I understand that you are establishing a new variable $a as an object to contain the output of $colResults, but I'm not sure what else is happening. Would you mind a blow-by-blow?
In the meantime, thanks again. It was right on the first attempt.
PropertiesToLoad.Add returns a value, a count of properties. It's not very interesting, Voiding that is one way of dropping the value so it doesn't appear when the code runs. Otherways include redirecting the output to Null, or assigning it to a variable (say $Return) and ignoring it.
For the sake of discussion, I would take a few short cuts in the code above :)
Using $Null in place of the directory entry ($objDomain) will have it use the default value, the current domain.
The Filter can be passed in as a parameter when creating the Directory Searcher.
The SearchScope defaults to subtree so has been removed from the code (if you want to see that, just run "$DirSearcher" on its own with the example below, it'll show you the values set).
Using PropertiesToLoad.AddRange saves us a loop through each properties. AddRange doesn't return a value either so there's no need to Void it or deal with the returned value. It needs an array as the parameter, which is why $PropList is @("value1", "value2") now.
Using Select-Object with a custom value allows us to skip creation of a new object and separate addition of a property to that object. It also loses the other loop.
Finally, you may also consider grabbing these:
http://www.quest.com/power
Because those will shorten your code to this:
Get-QADComputer -Name "FBX*" | Select-Object Name | Export-CSV "somefile.csv"
PowerShell is fun ;)
Chris
Chris is correct on the use of void.
$a = New-Object PSObject
- this creates a new object, the idea is to create a rich object with properties, and this provides the base object for us to add properties to.
$a | Add-Member -MemberType NoteProperty -Name Name -Value $_.Properties.Item("Name")
- this adds a property to $a called Name with the value of $_.Properties.Item("Name")
$a
- this outputs the object we just created to the pipeline so it is passed to Export-Csv
I'm probably not explaining this great, and I didn't find any really good references out there either. Have a look at this and see if you can make sense of it:
http://thepowershellguy.co
Business Accounts
Answer for Membership
by: peter_fieldPosted on 2009-05-02 at 17:12:29ID: 24288165
That was harder than I expected.. try this:
Select allOpen in new window