Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Newbie: manually outputting to CSV

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 07-04-2008   #1 (permalink)
Kurt
Guest


 

Newbie: manually outputting to CSV

Given this simple script;

$timestamp = Get-Date -Format "yyyy/MM/dd HH:mm"
$computer_name = (Get-WmiObject win32_computersystem | select
name).name

output_header
output_body($timestamp,$computer_name,"COMPUTER_NAME",$computer_name,
"", "")

function output_header
{
$label = "TIMESTAMP","SOURCE","ELEMENT","VALUE1","VALUE2","VALUE3"
$csvstring = Join-String $label -Separator "~"
$csvstring
}

function output_body([string] $ts,[string] $src,[string] $v1,[string]
$v2,[string] $v3)
{
$line = $ts, $src, $v1, $v2, $v3
$csvstring2 = Join-String $line -Separator "~"
$csvstring2
}

Why does it output the body portion differently than the header
portion, see below;

TIMESTAMP~SOURCE~ELEMENT~VALUE1~VALUE2~VALUE3
2008/07/04 09:59 FBYC3F1 COMPUTER_NAME FBYC3F1 ~~~~


My System SpecsSystem Spec
Old 07-04-2008   #2 (permalink)
Tao Ma
Guest


 

Re: Newbie: manually outputting to CSV

Hi Kurt,
Quote:

> output_body($timestamp,$computer_name,"COMPUTER_NAME",$computer_name,
output_body $timestamp $computer_name ...
Quote:

> "", "")
In PowerShell, () causes powershell wrapping the items into array. So all of
arguments stored in $ts.

Best regards,
Tao Ma

"Kurt" <kharless@xxxxxx>
??????:8a46f05d-913d-4d48-8896-78cc06b623d2@xxxxxx
Quote:

> Given this simple script;
>
> $timestamp = Get-Date -Format "yyyy/MM/dd HH:mm"
> $computer_name = (Get-WmiObject win32_computersystem | select
> name).name
>
> output_header
> output_body($timestamp,$computer_name,"COMPUTER_NAME",$computer_name,
> "", "")
>
> function output_header
> {
> $label = "TIMESTAMP","SOURCE","ELEMENT","VALUE1","VALUE2","VALUE3"
> $csvstring = Join-String $label -Separator "~"
> $csvstring
> }
>
> function output_body([string] $ts,[string] $src,[string] $v1,[string]
> $v2,[string] $v3)
> {
> $line = $ts, $src, $v1, $v2, $v3
> $csvstring2 = Join-String $line -Separator "~"
> $csvstring2
> }
>
> Why does it output the body portion differently than the header
> portion, see below;
>
> TIMESTAMP~SOURCE~ELEMENT~VALUE1~VALUE2~VALUE3
> 2008/07/04 09:59 FBYC3F1 COMPUTER_NAME FBYC3F1 ~~~~
>

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Outputting variables & accepting keystrokes without pressing enter Kari PowerShell 1 08-08-2008 10:30 AM
how to manually index? Neerav Vista General 7 01-03-2008 04:11 PM
Combining 2 files and outputting one Marco Shaw PowerShell 4 11-21-2006 06:44 PM
help. How to remove rc2 manually hayate PowerShell 3 11-17-2006 05:16 AM
Outputting to file as a byte stream Keith Hill [MVP] PowerShell 8 08-21-2006 12:25 PM


Vistax64.com 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 2005-2008

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 47 48 49 50 51