Well, I knew I wouldn't be satisfied. The other day I shared a PowerShell prompt function that could display telemetry like information for a few remote servers. One of the drawbacks was the limited amount of information I could display. I've revised that function and have a new version that displays additional information via a few performance counters. I've also reorganized the function to make it a bit more efficient. Want to see it?
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
Enhanced Display
This version still reads a list of computer names. I'd still recommend keeping this list brief. Although I have modified the prompt display so that each server has its own line.
This version of the function calls Get-Counter to retrieve additional information.
#define a list of performance counters $c = "\processor(_total)\% processor time", "\physicaldisk(_total)\% disk time", "\server\bytes total/sec", "\system\file control operations/sec" #create a hashtable of counters and values get-counter -Counter $c | select-object -ExpandProperty countersamples | foreach-object -Begin {$counterhash = @{}} -process { $counterHash.add($_.Path.split("\\")[-1], [math]::round($_.CookedValue, 2)) }
The counter data is added to the output for each server.
For visual interest, I'm using a hashtable of character values. The tricky part was padding values to get everything to line up. Even so, there may be instances where data doesn't completely line up. This generally resolves itself the next time you refresh.
Creating a One Command Session
I also am trying something new with this prompt. When you run a command, PowerShell wants to automatically invoke the prompt function. I inserted a Pause command (which only works on Windows). When you press Enter, the screen is cleared and you get your monitoring display at the top of the PowerShell console.
If you are only using the PowerShell console to occasionally run a command or merely want to periodically refresh the data, this might be useful. However, you can toggle this feature. When you load the prompt, PowerShell will define a global variable called PromptClear with a value of $True. Run $PromptClear = $False to turn off the pause and clear. Set it back to $True to turn it back on.
Get the PowerShell Code
By now some of you are chomping to give this a shot. The file is hosted on GitHub.
What do you think? Have I taken this concept far enough? Is this practical for any of you? What have you done to make this work for you? I hope you find this useful or at least pick up a tip or two from the code. Enjoy.
2 thoughts on “The Ultimate PowerShell Telemetry Prompt”
Comments are closed.