Pipe or output to a file

by energy99 at 2013-03-02 21:47:22

I’m running the following little script to get the file size or a specific file, this works great. I would like to pipe\output the results to a file but all I get is an empty file… below is the script…

Get-ChildItem $filepath | ForEach-Object { Write-Host $.name,==> ($.Length/1MB).tostring(“0.00”)MB }
by DonJ at 2013-03-02 22:36:46
Use write-output. Never ever use write-host. You can’t pipe from the host.
by NachumElla at 2013-03-03 02:41:46
Hello there!
I want to reproduce your problem, but I cant understand what you’re trying to achieve.
You want to know the size of “d:\report.log”?

Well, if you do, Here’s a way (in bytes):
”{0:N0}" -f (Get-ChildItem d:\report.log | select -ExpandProperty Length)
Another way (KiloBytes):
(Get-ChildItem d:\report.log).length / 1KB

If it’s not the case, I need more info.