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 - How to display screen output to text file in PowerShell

Reply
 
Old 08-08-2008   #1 (permalink)
Vinod K


 
 

How to display screen output to text file in PowerShell

I want to display the longname(name) and shortname of the output displayed on
Powershell screen to a text file.

$a = dir *.* | foreach { $_.name }
$a
$b = $a | tee-object -file e:\scripts\name.txt | sort

foreach($a in $b) {
write-host $a.substring(0,4),~1.xml

The Output displayed on PS screen is given below:
name.ps1
name.txt
sample.ps1
sample.txt

nam ~1.xml
nam ~1.xml
sam ~1.xml
sam ~1.xml

- I want to display the above outputs nam ~1.xml, sam ~1.xml to a text file
in 2 columns as Longname(name) and shortname.

Please help me out... I m awaiting your response



My System SpecsSystem Spec
Old 08-08-2008   #2 (permalink)
Neil Chambers


 
 

Re: How to display screen output to text file in PowerShell

there are a plethora of ways to accompish this. If you are just concerned
with the text output (which I assume you are as you don't want the screen
output to be in columns) then here is one way of doing it:

ls | sort name | %{"$($_.name) $($_.name.substring(0,4))~1.xml" >>
myfile.txt}

cheers,
n


"Vinod K" <Vinod K@xxxxxx> wrote in message
news:7A14038A-1219-459B-8A67-7EABE5A0CE0C@xxxxxx
Quote:

>I want to display the longname(name) and shortname of the output displayed
>on
> Powershell screen to a text file.
>
> $a = dir *.* | foreach { $_.name }
> $a
> $b = $a | tee-object -file e:\scripts\name.txt | sort
>
> foreach($a in $b) {
> write-host $a.substring(0,4),~1.xml
>
> The Output displayed on PS screen is given below:
> name.ps1
> name.txt
> sample.ps1
> sample.txt
>
> nam ~1.xml
> nam ~1.xml
> sam ~1.xml
> sam ~1.xml
>
> - I want to display the above outputs nam ~1.xml, sam ~1.xml to a text
> file
> in 2 columns as Longname(name) and shortname.
>
> Please help me out... I m awaiting your response
>
>
My System SpecsSystem Spec
Old 08-08-2008   #3 (permalink)
Vinod K


 
 

Re: How to display screen output to text file in PowerShell

Hi Neil,

Could u provide the code so to accomplish my task in many ways...

--Vinod K

"Neil Chambers" wrote:
Quote:

> there are a plethora of ways to accompish this. If you are just concerned
> with the text output (which I assume you are as you don't want the screen
> output to be in columns) then here is one way of doing it:
>
> ls | sort name | %{"$($_.name) $($_.name.substring(0,4))~1.xml" >>
> myfile.txt}
>
> cheers,
> n
>
>
> "Vinod K" <Vinod K@xxxxxx> wrote in message
> news:7A14038A-1219-459B-8A67-7EABE5A0CE0C@xxxxxx
Quote:

> >I want to display the longname(name) and shortname of the output displayed
> >on
> > Powershell screen to a text file.
> >
> > $a = dir *.* | foreach { $_.name }
> > $a
> > $b = $a | tee-object -file e:\scripts\name.txt | sort
> >
> > foreach($a in $b) {
> > write-host $a.substring(0,4),~1.xml
> >
> > The Output displayed on PS screen is given below:
> > name.ps1
> > name.txt
> > sample.ps1
> > sample.txt
> >
> > nam ~1.xml
> > nam ~1.xml
> > sam ~1.xml
> > sam ~1.xml
> >
> > - I want to display the above outputs nam ~1.xml, sam ~1.xml to a text
> > file
> > in 2 columns as Longname(name) and shortname.
> >
> > Please help me out... I m awaiting your response
> >
> >
>
>
My System SpecsSystem Spec
Old 08-08-2008   #4 (permalink)
Neil Chambers


 
 

Re: How to display screen output to text file in PowerShell

They all depend on the final requirements.

If you can tell me a little more about exactly what it is you're trying to
achieve then I can provide more examples. The one I provided gives you two
columns in a file which is pretty much all you asked for

n

"Vinod K" <VinodK@xxxxxx> wrote in message
news:8DBD07C9-F275-4CFC-8AA1-AFA8A0D7904B@xxxxxx
Quote:

> Hi Neil,
>
> Could u provide the code so to accomplish my task in many ways...
>
> --Vinod K
>
> "Neil Chambers" wrote:
>
Quote:

>> there are a plethora of ways to accompish this. If you are just concerned
>> with the text output (which I assume you are as you don't want the screen
>> output to be in columns) then here is one way of doing it:
>>
>> ls | sort name | %{"$($_.name) $($_.name.substring(0,4))~1.xml" >>
>> myfile.txt}
>>
>> cheers,
>> n
>>
>>
>> "Vinod K" <Vinod K@xxxxxx> wrote in message
>> news:7A14038A-1219-459B-8A67-7EABE5A0CE0C@xxxxxx
Quote:

>> >I want to display the longname(name) and shortname of the output
>> >displayed
>> >on
>> > Powershell screen to a text file.
>> >
>> > $a = dir *.* | foreach { $_.name }
>> > $a
>> > $b = $a | tee-object -file e:\scripts\name.txt | sort
>> >
>> > foreach($a in $b) {
>> > write-host $a.substring(0,4),~1.xml
>> >
>> > The Output displayed on PS screen is given below:
>> > name.ps1
>> > name.txt
>> > sample.ps1
>> > sample.txt
>> >
>> > nam ~1.xml
>> > nam ~1.xml
>> > sam ~1.xml
>> > sam ~1.xml
>> >
>> > - I want to display the above outputs nam ~1.xml, sam ~1.xml to a text
>> > file
>> > in 2 columns as Longname(name) and shortname.
>> >
>> > Please help me out... I m awaiting your response
>> >
>> >
>>
>>
My System SpecsSystem Spec
Old 08-08-2008   #5 (permalink)
Kiron


 
 

RE: How to display screen output to text file in PowerShell

# create a calculated property and use [Scripting.FileSystemObject]'s
# GetFile Method, then get the file's ShortName Property
$fso = new-object -c scripting.fileSystemObject
$shortName = @{label = 'Short'
expression = {$fso.getFile($_.fullname).shortName}}

ls | ? {!$_.psIsContainer} | ft Name, $shortName > names.txt

--
Kiron
My System SpecsSystem Spec
Old 08-08-2008   #6 (permalink)
Keith Hill [MVP]


 
 

Re: How to display screen output to text file in PowerShell

"Kiron" <Kiron@xxxxxx> wrote in message
news:A0A58ED8-C80C-4386-B5A9-20A30D5895F9@xxxxxx
Quote:

> # create a calculated property and use [Scripting.FileSystemObject]'s
> # GetFile Method, then get the file's ShortName Property
> $fso = new-object -c scripting.fileSystemObject
> $shortName = @{label = 'Short'
> expression = {$fso.getFile($_.fullname).shortName}}
>
> ls | ? {!$_.psIsContainer} | ft Name, $shortName > names.txt
>
Note that if you are using PSCX you can use the Get-ShortPath cmdlet and
skip using the FileSystemObject:

ls | ? {!$_.PSIsContainer} | ft Name, @{l='Short';e={Get-ShortPath $_}} >
names.txt

--
Keith

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: Send command line via WMI - Pipe output to text file on remote PowerShell
Output all content of text file in different columns PowerShell
Newbie - Output to a text file problem. PowerShell
output .ps1 script to text file PowerShell
Reccording DOS output to a text file Vista security


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