Powershell - Output Color RRS feed

  • Question

  • Hi all,

    I am running the code below and it works. What I am trying to do is, in the results when Enabled properties is True I would like to the text 'True' foreground color to be green otherwise if 'false' color Red.

    The same with the Password never expires properties, if the result is True I would like to the text 'True' foreground color to be Red otherwise if 'False' color green.

    I have looked around several site and done search but cant seem to find something that would fit my request.


                Get-ADUser "user name"  -Properties Enabled,LockedOut,DisplayName,GivenName, SurName,Mail,LastLogon, Created,passwordlastset,Passwordneverexpires,msDS-UserPasswordExpiryTimeComputed, Description, office, Canonicalname | `
                Select-Object Enabled, 
                @{Expression={$_.DisplayName};Label='Display Name';},
                @{Expression ={$_.GivenName};Label='Name';}, `
                @{Expression ={$_.SurName}; Label='Last Name'; }, 
                @{Expression ={[DateTime]::FromFileTime($_.LastLogon)}; Label='Last Logon';}, 
                @{Expression={$_.Created};Label='Date Created';}, 
                @{Expression={$_.passwordlastset};Label='PW Last Reset';}, 
                @{Expression={$_.Passwordneverexpires};Label='PW Never Expires';},
                @{Name="PW Exp Date";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}  ,
    Any pointers would be appreciated.

    Sincerely and regards,


    Saturday, September 2, 2017 5:14 AM


All replies

  • Adding screen shot of results:


    Saturday, September 2, 2017 5:16 AM
  • Have you tried using a paint brush.  Some I know have used a crayon.  They just take it and rub it on the screen.

    In my experience I have found that PowerShell documentation and Windows documentation say that color is not supported in "console" applications.

    There is one small method that remains highly controversial and does not require having attended kindergarten or even having to read the PowerSHell documentation.  We can use this trick to make crayon-like colors

    Write-Host "this is the color RED' -fore red
    Write-Host "this is the color GREEN' -fore green

    Try it.

    The other famous trick is to use HTML: http://tech-comments.blogspot.com/2012/07/powershell-dynamically-color-posh.html

    Of course that requires that you know your primary colors.


    • Edited by jrv Saturday, September 2, 2017 7:38 AM
    Saturday, September 2, 2017 7:34 AM
  • I found the solution at another site:

    Powershell - Output Color for certain results


    • Marked as answer by Jo Srm Sunday, September 3, 2017 1:56 AM
    Sunday, September 3, 2017 1:56 AM