by mohdazam89 at 2013-02-05 21:49:29
Hi,by DonJ at 2013-02-06 06:48:20
I am trying to create a tool for display comp info, disk info, service status…
Everything is working fine.
I have a question, i want to dispaly the stopped serivce in red or disk usage if below 10% should be displayed in red.
for example…disk info.
The tool uses primal forms.
$richTextBox1.Text is for instering servername
$richTextBox2.Text for dispalying the result
Buttons to execute the functions.
Function disk {
$richTextBox2.Text = $richTextBox2.Text.Clear
$s=$richTextBox1.Text.split("`n")
$info=Get-WmiObject win32_logicaldisk -computername $s -filter "drivetype=3"|
Format-Table @{Name="Server Name";Expression={"{0:N1}" -f($.systemname)}},deviceid,volumename,@{Name="Size(GB)";Expression={"{0:N1}" -f($.size/1gb)}},@{Name="FreeSpace(GB)";Expression={"{0:N1}" -f($.freespace/1gb)}},@{Name="Freepercent%";Expression={"{0:N1}" -f([Math]::Round(($.freespace / $_.size) * 100, 2))}} -autosize | out-string
$richtextbox2.Appendtext($info)
}
===
Displays the disk info of a computer. But displays in black font . I want it to display in red font if the freepercent is below 10%.
Please assist.
Thanks
Azam
You’d need to look at the documentation for the RichTextBox control in MSDN - I don’t know how to do that myself. Honestly… this displaying of information in an RTF is gonna drive you crazy. I’ll tell you the same thing I told this guy (viewtopic.php?f=2&t=1167) - look into HTML instead. If you use the EnhancedHTML module in my "HTML Reports" ebook (it’s free at powershellbooks.com), you can do a much better job of coloring, and it has an example of exactly what you’re asking. You can display the resulting HTML in your dialog box by using a WebView control. And it’ll look a lot nicer.by mohdazam89 at 2013-02-06 07:58:05
But… if you want to keep using RTF, you’ll need to read the docs at http://msdn.microsoft.com/en-us/library … 80%29.aspx. Expect it to be a pain.
Thanks a Lot Jones,
Pleasure receiving a response from the powershell guru…
Sure will look into the ebook
Have a great Day…
Thanks
Azam