![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | writing out to file Hello everyone; I'm writing a one-line to take the recursive contents of a directory and write its contents out to file with send prefixed in front of the $_.name object. It goes like this: dir -recurse | ForEach-Object { write-host send $_name } | Out-File ftp_batch.txt but it does not write to file. Any pointers? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: writing out to file "Braden C. Roberson-Mailloux" <bray@xxxxxx> wrote in message news:#Z$oFd5tIHA.1220@xxxxxx Quote: > Hello everyone; > > I'm writing a one-line to take the recursive contents of a directory and > write its contents out to file with send prefixed in front of the $_.name > object. > > It goes like this: > > dir -recurse | ForEach-Object { write-host send $_name } | Out-File > ftp_batch.txt > > but it does not write to file. > > Any pointers? host's UI and can't be redirected to a file using Out-File or >. You want to use Write-Output instead. Second, you are missing a '.' between $_ and name. Finally since you want to put the "send" and the name on the same line you should do this: dir -r | foreach { "send $($_.name)" } > ftp_batch.txt Note that when PowerShell sees a string like "send $($_.name)" it implicitly outputs it just as if you had written - write-output "send $($_.name)". -- Keith |
My System Specs![]() |
| | #3 (permalink) |
| | Re: writing out to file Thanks for the response, Keith. I'll give this a shot and report back. "Keith Hill [MVP]" <r_keith_hill@xxxxxx_no_spam_I> wrote in message news:8882F6B5-7458-4648-9510-BB6AE0C7C670@xxxxxx Quote: > "Braden C. Roberson-Mailloux" <bray@xxxxxx> wrote in message > news:#Z$oFd5tIHA.1220@xxxxxx Quote: >> Hello everyone; >> >> I'm writing a one-line to take the recursive contents of a directory and >> write its contents out to file with send prefixed in front of the $_.name >> object. >> >> It goes like this: >> >> dir -recurse | ForEach-Object { write-host send $_name } | Out-File >> ftp_batch.txt >> >> but it does not write to file. >> >> Any pointers? > First you don't want to use Write-Host since that writes directly to the > host's UI and can't be redirected to a file using Out-File or >. You want > to use Write-Output instead. Second, you are missing a '.' between $_ and > name. Finally since you want to put the "send" and the name on the same > line you should do this: > > dir -r | foreach { "send $($_.name)" } > ftp_batch.txt > > Note that when PowerShell sees a string like "send $($_.name)" it > implicitly outputs it just as if you had written - write-output "send > $($_.name)". > > -- > Keith |
My System Specs![]() |
| | #4 (permalink) |
| | Re: writing out to file It works. Awesome. "Keith Hill [MVP]" <r_keith_hill@xxxxxx_no_spam_I> wrote in message news:8882F6B5-7458-4648-9510-BB6AE0C7C670@xxxxxx Quote: > "Braden C. Roberson-Mailloux" <bray@xxxxxx> wrote in message > news:#Z$oFd5tIHA.1220@xxxxxx Quote: >> Hello everyone; >> >> I'm writing a one-line to take the recursive contents of a directory and >> write its contents out to file with send prefixed in front of the $_.name >> object. >> >> It goes like this: >> >> dir -recurse | ForEach-Object { write-host send $_name } | Out-File >> ftp_batch.txt >> >> but it does not write to file. >> >> Any pointers? > First you don't want to use Write-Host since that writes directly to the > host's UI and can't be redirected to a file using Out-File or >. You want > to use Write-Output instead. Second, you are missing a '.' between $_ and > name. Finally since you want to put the "send" and the name on the same > line you should do this: > > dir -r | foreach { "send $($_.name)" } > ftp_batch.txt > > Note that when PowerShell sees a string like "send $($_.name)" it > implicitly outputs it just as if you had written - write-output "send > $($_.name)". > > -- > Keith |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Writing to IE or a file won't work | VB Script | |||
| Writing File to CD ROM | VB Script | |||
| Problem Writing file to CD | .NET General | |||
| writing output to XML file | PowerShell | |||
| Writing to a file with out-file or export-csv | PowerShell | |||