Powershell Tip: Formatting trick to make your search criteria stand out
As I mentioned in a post earlier this week, I really like the many formatting options in Powershell. Here’s another formatting tip not well-documented in my experience. Let’s take this example in which we are looking at whether agent proxy is enabled on my Operations Manager 2007 agents. I want to print all agents and their agent proxy status to the screen, but I want to be able to quickly identify agents where agent proxy is NOT enabled.
This is quite easily done with a foreach loop and the Powershell equivalent of the if-then statement to change the color of the text based on the value of the ProxyEnabled status for each agent. In this case, if ProxyEnabled = false, text output will be RED. If ProxyEnabled = true, text output will be GREEN. I have commented the sample script below to clarify the meaning of each statement.
#Retrieve all agents and assign to a variable
$agents = get-agent
#For each agent in the $agents variable, execute the IF statement
foreach ($agent in $agents){
#If ProxyEnabled = TRUE, write agent Name and ProxyEnabled status to the console in RED.
If ($agent.ProxyingEnabled -match $true) {write-host $agent.name, $agent.proxyingenabled -foregroundcolor “red”}
else
#If ProxyEnabled = FALSE write agent Name and ProxyEnabled status to the console in GREEN.
{write-host $agent.name, $agent.proxyingenabled -foregroundcolor “darkgreen”}
}
Have something you’d like to do with the Command Shell but can’t quite figure out how? Drop me a line via the Contact page.
Update your MOM 2005 skills to Operations Manager 2007 at the Operations Manager Bootcamp! Check the 2008 Bootcamp Schedule and request pricing and availability HERE.

March 25th, 2008 at 7:49 am
[…] As I mentioned in a post earlier this week, I really like the many formatting options in Powershell. Heres another formatting tip not well-documented in my experience. Lets take this example in which we are looking at whether agent proxy is enabled on my Operations Manager 2007 agents. I want to print all agents and their agent proxy status to the screen, but I want to be able to quickly identify agents where agent proxy is NOT enabled.(continue at source) […]