"Braden C. Roberson-Mailloux" <bray@xxxxxx> wrote in message
news:#Z$oFd5tIHA.1220@xxxxxx
> 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