![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| | #6 (permalink) |
| | 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 > skip using the FileSystemObject: ls | ? {!$_.PSIsContainer} | ft Name, @{l='Short';e={Get-ShortPath $_}} > names.txt -- Keith |
My System Specs![]() |
![]() |
| 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 | |||