Code Monkey home page Code Monkey logo

Comments (3)

joonro avatar joonro commented on July 29, 2024

Hi -

This looks interesting. I only tried the second example from the link you provided. It does not work if you use it like this:

Get-ChildItemColor  | Select-Object Name, @{Name="Size";Expression={Format-FileSize($_.Length)}}

because Get-ChildItemColor just changes $Host.UI.RawUI.ForegroundColor right before printing an item, and the pipe will not get the color information.

However, if you do the following:

Function Format-FileSize() {
    Param ([int]$size)
    If     ($size -gt 1TB) {[string]::Format("{0:0.00} TB", $size / 1TB)}
    ElseIf ($size -gt 1GB) {[string]::Format("{0:0.00} GB", $size / 1GB)}
    ElseIf ($size -gt 1MB) {[string]::Format("{0:0.00} MB", $size / 1MB)}
    ElseIf ($size -gt 1KB) {[string]::Format("{0:0.00} kB", $size / 1KB)}
    ElseIf ($size -gt 0)   {[string]::Format("{0:0.00} B", $size)}
    Else                   {""}
}

$Host.UI.RawUI.ForegroundColor = "Red"

Get-ChildItem | Select-Object Name, @{Name="Size";Expression={Format-FileSize($_.Length)}}

You will see that everything is red now, so one way to do this is creating a function which incorporates the coloring as well as Select-Object Name, @{Name="Size";Expression={Format-FileSize($_.Length)}} part.

Unfortunately I don't have time to implement this at the moment, but I would be happy to accept a PR if you want to open one. I'm sorry!

from get-childitemcolor.

sphr2k avatar sphr2k commented on July 29, 2024

Hi,
thanks for you reply :) I'm afraid I'm not very capable when it comes to more complex PowerShell stuff - maybe I'll to get it working if I find the time. Cheers, Jan

from get-childitemcolor.

joonro avatar joonro commented on July 29, 2024

Hi,

I just incorporated PSColor's implementation, and this should be working now.

from get-childitemcolor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.