Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to run multiple Get Commands to retrieve AD information. I piped all of these commands and now I want to write the output to write all the the information ito one csv but at the moment i am getting "a parameter can not be found that matches parameter named 'append'

    $OutFile = "C:\Results.csv"

#This gets the managedBy and name
$Domain=Get-addomain|select-object ManagedBy,Name | Export-csv -Path $OutFile -append -notypeinformation

#This gets the distinguished name
$Users=Get-ADUser -Filter *|select-object DistinguishedName | Export-csv -Path $OutFile -append -NoTypeInformation

#Gets User
$ADUsers=Get-ADUser -filter *| Export-csv -Path $OutFile -append -NoTypeInformation
share|improve this question
1  
What does a google search turn up when looking for that error message? Hint: the first result gives you the answer to your problem. –  John Jun 25 at 16:48
    
What version of Powershell are you using? –  BigHomie Jun 25 at 16:59
    
I am using powershell 2.0 I am going to try and use the clues provided below to help me. –  user3772927 Jun 25 at 22:24

2 Answers 2

up vote 1 down vote accepted

What may work for you is to use arrays to create new objects that you can then output to a csv file. I've extracted the relevant portions of code I have used before (the names of variables have been changed to protect the innocent :) ) that should allow you to get the idea of how to make this work (and some google searches can fill in any other missing pieces):

Initialize the arrays you will be working with

$objOut = @()
$objWork= @()

Loop through the objects in a list - assumes that you will be building the csv from multiple answers/data that you will loop through to gather

Foreach ($objList in $list){

Within loop, assign to objwork the values that you will be adding to array, think of it as adding records in a DB. Assume that you are doing work here to gather your data that will populate the values for $firstvalue and $secondvalue (such as the AD calls you have)

$objWork = New-Object System.Object
$objWork | Add-Member -type NoteProperty -name header1 -value $firstvalue
$objWork| Add-Member -type NoteProperty -name header2 -value $secondvalue
$objOut += $objWork
}

Export the array of all the user details to a CSV file for consumption (yum!)

$objOut | Export-CSV C:\results.csv

share|improve this answer

I get an entirely different error, on the third command.

Export-csv : Cannot append CSV content to the following file: Results.csv. The appended object does not have a property that corresponds to the following column: ManagedBy. To continue with mismatched properties, add the -Force parameter, and then retry the command.

Which makes sense. You can't put different columns into a single CSV file. Export to plain text, or use multiple CSV files.

share|improve this answer
    
but what if i want them to all end up in one csv in the end? is it a case of exporting then re-importing? or its impossible –  user3772927 Jun 25 at 16:58
    
You're misunderstanding how Powershell works with CSV. It "knows" that the first row is supposed to be the column headers. So, you can't create a CSV with one set of columns, and then append to it with different columns. Why would you even want that? Just use plain text, if that's what you're after. –  mfinni Jun 25 at 17:00
    
Okay thanks that kind of makes sense I need to go and read around it a bit more then, why I wanted to so it like that was because i needed to check for different AD things and put then in a csv format –  user3772927 Jun 25 at 17:04
1  
@user3772927 in that case ... Or in any case, you're doing it wrong. Use one Get command and a filter to select only the 3 (?) attributes you actually want, and export those to csv. –  HopelessN00b Jun 25 at 17:04
    
Thanks from that will look at the get commands to see which ones gets me everything i need. –  user3772927 Jun 25 at 17:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.