Answered by:
Powershell - Output Color

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.
Code:
Get-ADUser "user name" -Properties Enabled,LockedOut,DisplayName,GivenName, SurName,Mail,LastLogon, Created,passwordlastset,Passwordneverexpires,msDS-UserPasswordExpiryTimeComputed, Description, office, Canonicalname | ` Select-Object Enabled, @{Expression={$_.LockedOut};Label='Locked';}, @{Expression={$_.DisplayName};Label='Display Name';}, @{Expression ={$_.GivenName};Label='Name';}, ` @{Expression ={$_.SurName}; Label='Last Name'; }, Mail, @{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")}} , Description, Office, Canonicalname Format-list
Any pointers would be appreciated.Sincerely and regards,
Regards
Saturday, September 2, 2017 5:14 AM
Answers
All replies
-
Adding screen shot of results:
Regards
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 greenTry 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 -