-2

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
3
  • 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, 2014 at 16:48
  • What version of Powershell are you using?
    – MDMoore313
    Jun 25, 2014 at 16:59
  • I am using powershell 2.0 I am going to try and use the clues provided below to help me. Jun 25, 2014 at 22:24

2 Answers 2

1

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

0

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.

5
  • 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 Jun 25, 2014 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, 2014 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 Jun 25, 2014 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. Jun 25, 2014 at 17:04
  • Thanks from that will look at the get commands to see which ones gets me everything i need. Jun 25, 2014 at 17:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .