Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Export to csv with custom column headers

Reply
 
Old 01-20-2009   #1 (permalink)
jmedd


 
 

Export to csv with custom column headers

I have some code which does the following:

$servers = 'servera','serverb'

foreach ($server in $servers){

Get-ChildItem "\\$server\c$\folder" | Select-Object name,lastwritetime
}

i.e. it returns all the files in the remote folder for each server and
returns the name of the file and the time it was last written to.

I need to extend this futher by taking the returned list of files and
lastwritetime and export to a csv which has the file names as the column
headers (they will be the same for each server) , the row label as the server
name and the data as the lastwritetime.

So far I can only get it to export to individual csv's for each server and
name,lastwritetime are the column headers.

Anyone able to help?

Thanks

My System SpecsSystem Spec
Old 01-20-2009   #2 (permalink)
PaulChavez


 
 

RE: Export to csv with custom column headers

Here you go. This should give you one row per server with the column heading
being the filenames and the data being the last write time. One column is the
name of the server as well.




$servers = 'servera','serverb'
$filedata = @()

foreach ($server in $servers){

$files = Get-ChildItem "\\$server\c$\folder" |
Select-Object name,lastwritetime

$entry = new-object psobject
$entry | add-member noteproperty server $server
$files | foreach {
$entry | add-member noteproperty $_.name $_.lastwritetime
}
$filedata += $entry
}



"jmedd" wrote:
Quote:

> I need to extend this futher by taking the returned list of files and
> lastwritetime and export to a csv which has the file names as the column
> headers (they will be the same for each server) , the row label as the server
> name and the data as the lastwritetime.
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Is it possible in "computer" to view files from top to bottom in 1st column then same again in next column to the right etc? Vista file management
Custom Mail Headers with Windows Mail Vista mail
Export-CliXml/Export-Csv: Change to Export-Object? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46