Hi,
I am running a report in powershell to get devices in 2 different variables
1= all device pending wipe = $staledevices
2nd =all devices that need to be deleted $deletedevices
i want to combine those 2 list of devices into 1 csv write now it just out puts on screen
Hi James. First things first, when sharing any kind of code (even error text) it’s helpful to use the </> “Preformatted Text” button and place your code between the backticks, like this:
so that the forum will render it like this:
Export-Csv
With that being said, I see at least one syntax error for sure that might be part of the problem, but first I don’t know what “** |” means at the beginning of your example. What are the double asterisks representing?
Going off some assumptions here’s what I think maybe you should be trying:
Let’s talk through this specifically using “object” language since Powershell is an object-oriented language. $StaleDevices and $DeletedDevices are variables, and each one is likely an Array object containing objects with several properties. Export-Csv is great with objects that have multiple properties because it creates a header row based on all of the shared property names, and then prints the values for each object in the appropriate columns.
In the above example we’re assuming that both arrays contain objects with identical properties. By calling both variables separated by a comma we’re just telling Powershell to send all of the objects to the pipeline to be handled by Export-Csv. We provide a destination filename for Export-Csv and also importantly we use the “NoTypeInformation” switch parameter which tells Export-Csv not to print the object type as the first row in the CSV file.
I found the post interesting because I never thought of trying to export 2 sets of arrays at once so I tried it out. On this query I dont get the results expected. See Below: