Pipe or output to a file

Welcome Forums General PowerShell Q&A Pipe or output to a file

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years, 2 months ago.

  • Author
  • #5617

    Points: 0
    Rank: Member

    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.

The topic ‘Pipe or output to a file’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort