You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added help documentation
updated README
Added samples
Reverted Get-PSWho to not trim when using -AsString
Added code to New-CustomFileName to preserve case for non-placeholders
Modified Out-VerboseTee to turn on VerboseTee
#TODO separate into parameter sets for simple or complex conditions
4
-
#todo: avoid coloring the header
1
+
5
2
FunctionOut-ConditionalColor {
6
-
<#
7
-
.Synopsis
8
-
Display colorized pipelined output.
9
-
.Description
10
-
This command is designed to take pipeline input and display it in a colorized format, based on a set of conditions. Unlike Write-Host which doesn't write to the pipeline, this command will write to the pipeline. You can get colorized data and save the output to a variable at the same time, although you'll need to use the common OutVariable parameter (see examples).
11
-
12
-
The default behavior is to use a hash table with a property name and color. The color must be one of the standard console colors used with Write-Host.
13
-
14
-
$c = @{Stopped='Red';Running='Green'}
15
-
16
-
You can then pipe an expression to this command, specifying a property name and the hash table. If the property matches the key name, the output for that object will be colored using the corresponding hash table value.
17
-
18
-
get-service -diplayname windows* | out-conditionalcolor $c status
19
-
20
-
Or you can do more complex processing with an ordered hash table constructed using this format:
21
-
22
-
[ordered]@{ <comparison scriptblock> = <color>}
23
-
24
-
The comparison scriptblock can use $PSitem.
25
-
26
-
$h=[ordered]@{
27
-
{$psitem.ws -gt 200mb}='yellow'
28
-
{$psitem.vm -gt 500mb}='red'
29
-
{$psitem.cpu -gt 300}='cyan'
30
-
}
31
-
32
-
When doing a complex comparison you must use an [ordered] hashtable as each key will be processed in order using an If/ElseIf statement.
33
-
34
-
This command should be the last part of any pipelined expression. If you pipe to anything else, such as Sort-Object, you will lose your color formatting. Do any other sorting or filtering before piping to this command.
35
-
36
-
This command requires PowerShell 3.0 and later and works best in the PowerShell console. It won't do anything in the PowerShell ISE.
37
-
.ParameterConditions
38
-
Use a simple hashtable for basic processing or an ordered hash table for complex.
39
-
.ParameterProperty
40
-
When using a simple hash table, specify the property to compare using the -eq operator. If you don't specify a property you will be prompted.
Repeat the previous example, but save the output to the variable winstop. When you look at $Winstop you'll see the services, but they won't be colored. This example uses the parameters positionally.
49
-
.Example
50
-
PS C:\> get-eventlog system -newest 50 | out-conditionalcolor @{error='red';warning='yellow'}
51
-
Enter a property name: entrytype
52
-
53
-
Get the newest 50 entries from the System event log. Display errors in red and warnings in yellow. If you don't specify a property you will be prompted.
0 commit comments