locked
Changing Output Color RRS feed

  • Question

  • I am a beginner I powershell but have been working with it over the past several days.  Have created a script to display basic computer info (with a lot of help from  various youtube videos).

    Get-WMIObject win32_logicalDisk -ComputerName $env:computername | Select-Object SystemName, DeviceID, VolumeName,

      @{name="Size(GB)"; expression={"{0:N1}" -f ($_.size/1gb)}},
      @{name="FreeSpace(GB)"; expression={"{0:N1}" -f ($_.FreeSpace/1gb)}},
      @{name="%FreeSpace(GB)"; expression={"{0:N2}%" -f(($_.FreeSpace/$_.size)*100)}} ,
      @{name="Date"; expression={$(Get-Date -Format "g")}} | Format-Table -AutoSize 

     Am looking for help on changing the foreground color output (specifically of the %Freespace output) if for instance the %Freespace falls to less than 75%.  I know if involves an "if then" statement but after a whole afternoon of messing around with it I am reaching out to folks that have a lot more experience than me.  Thanks in advance for any help

     

     

    Tuesday, February 13, 2018 12:41 AM

All replies

  • That is not directly possible with PowerShell.  You will have to learn how to write a much more sophisticated program to be able to output in custom colors.

    You can output to HTML and customize that with colors but you will still have to learn more about programming in PowerShell.


    \_(ツ)_/

    Tuesday, February 13, 2018 1:00 AM
  • Then you are set.  Just write a program that combines the two.  Not that the output cannot be saved with that method.

    \_(ツ)_/

    Tuesday, February 13, 2018 1:09 AM
  • You will have to start by learning PowerShell.  You cannot use Write-Host that way.  It won't work.

    Learn PowerShell and you will understand why.

    Learn PowerShell  


    \_(ツ)_/

    Tuesday, February 13, 2018 1:31 AM
  • Perhaps starting by learning PowerShell would help you to learn something.

    Why are all of you kids so lazy.  Why haven't you been able to learn how to read technical material.


    \_(ツ)_/

    Tuesday, February 13, 2018 1:56 AM
  • Please try to understand that we cannot teach you PowerShell.

    What you are asking cannot be done as you want.  I am recommending that you first learn PowerShell to better understand how this works.  We cannot incrementally teach any complex technology and we cannot write your script for you.

    I posted a link to a basic video tutorial by MS.  It will get you started in a better direction.

    I started building my first computer in 1960.   I have been involved with engineering and technology ever since then. 

    If you search you will find many different ways to output colorized reports.

    Here is one to start with: http://tech-comments.blogspot.com/2012/07/powershell-dynamically-color-posh.html

    You will notice that it may takes some programming skill to understand.


    \_(ツ)_/

    Tuesday, February 13, 2018 2:57 AM
  • If you would stop being stubborn and actually learn PwoerShell you would understand why I am telling you that adding Write-Host into calculated select statement cannot work.  Write-Host cannot send output to a pipeline.  Until you can understand the terms and the syntax as well as what a pipeline is there is nothing we can tell you that will make you understand

    You knowledge of PowerShell is way short of a knowledgeable beginner. Once you accept that bit of wisdom you will be able to learn.

    Take the tutorial and stop wasting your time claiming you already know.


    \_(ツ)_/

    Tuesday, February 13, 2018 3:12 AM
  • One last thing, if you actually knew powershell it would be a "walk in the park" to help me with the syntax I needed to do what I want to do

    You cannot mix write-host into a computed select.  Read the help for write-host as  a starter.

    help write-host -online


    \_(ツ)_/

    • Proposed as answer by BOfH-666 Tuesday, February 13, 2018 9:10 AM
    Tuesday, February 13, 2018 3:15 AM
  • I think you really need to spend time learning how PowerShell works.  What you are asking is not possible by any normal means.

    Sorry but miracles ae not part of programming.


    \_(ツ)_/


    • Edited by jrv Tuesday, February 13, 2018 6:28 AM
    Tuesday, February 13, 2018 4:44 AM
  • It cannot be done with Write-Host and Format-Table no matter how you try or what you claim.  I gave you more that two methods fro colorizing output which you completely ignored.

    If you would learn PowerShell instead of harassing others to give you a canned solution you would find that this is not as hard as you are making it.

    Note that the forum rules state that we do not write custom solutions on request.   If some other forum wrote a solution for you then you have no reason to complain.


    \_(ツ)_/

    Wednesday, February 14, 2018 2:16 AM
  • What you have posted is not a solution.  It is just a picture.  How is that supposed to help anyone?

    You are too busy defending your eg and trying to prove you know something to be able to take advantage of any technical help.  Try to listen to those who are older and more experienced than you.  Don't just get mad when you don't get instant gratification.

    Technology takes studying and learning constantly.  When you post code that clearly shows you do not understand the basics of PowerShell and when you fail to understand simple articles explain how to do what you need then there is little we can do to help you.

    As I have already posted, this forum is not a free script writing forum and is not a free consulting forum.  The forums here can answer specific questions.

    I have no desire to debate this.  Over time some may sink in and become useful.  For know I am hglad you feel you have your solution.  Post the code and mark it as an answer.


    \_(ツ)_/

    Wednesday, February 14, 2018 4:39 AM