Reputation: 49
I am using a Powershell form to output some data and I am wondering how I can get the output in color?
I am not using write-host. That is not what I am looking for. I know you can use -ForegroundColor for that.
It's for Get-ADUser -Filter "UserPrincipalName -like 'Username'" | Select Enabled
If output is False it needs to be in Red. If output is true just regular color.
Anyone who can help me?
Many thanks. Ralph.
Upvotes: 1
Views: 1016
Reputation: 16116
A follow-up to my comment
#region Begin functions and code behind
function RunCode {
$ProcessList = (Get-Process).Name
If ($ProcessList -ge 10)
{$DataSet.ForeColor = 'red'}
else {$DataSet.ForeColor = 'black'}
[void] $DataSet.Items.Addrange($ProcessList)
}
#endregion End functions and code behind
#region Begin GUI code
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$Form = New-Object system.Windows.Forms.Form
$Form.ClientSize = '511,501'
$Form.text = "Form"
$Form.TopMost = $false
$RunCode = New-Object system.Windows.Forms.Button
$RunCode.text = "RunCode"
$RunCode.width = 90
$RunCode.height = 30
$RunCode.location = New-Object System.Drawing.Point(19,17)
$RunCode.Font = 'Microsoft Sans Serif,10'
$DataSet = New-Object system.Windows.Forms.ListBox
$DataSet.text = "listBox"
$DataSet.width = 204
$DataSet.height = 144
$DataSet.location = New-Object System.Drawing.Point(17,98)
$Form.controls.AddRange(@(
$RunCode,
$DataSet
))
$RunCode.Add_Click({ RunCode })
#endregion Begin GUI code
# Call the GUI
[void]$Form.ShowDialog()
Upvotes: 2