Archive

Posts Tagged ‘posh’

Just a bit of PoSh – show your battery level at the prompt

December 19th, 2008 jpavleck 2 comments

I’ve been working on a new, more condensed version of the OpsMgr PoSh library – one of the coolest features I think is the ‘location awareness’ which automatically switches your management server and such based on where you’re actually connected from.

Anyway, to do that I was embedding things in function prompt {}. In case you aren’t aware, if you define the prompt function, whatever is in there will run everytime you return to the prompt in the console. You can use this to your advantage for many things, such as this nifty little battery gauge that lets you know how much juice is left. It also has a configurable global variable, BatteryDisplayAtPercent, which you can set so it will hide until there is that much charge or less remaining.

First a screenshot, then the script:

battery-prompt

# ==============================================================================================
#
# Microsoft PowerShell Source File — Created with SAPIEN Technologies PrimalScript 2007
#
# NAME: Battery-Prompt.ps1
#
# AUTHOR: Jeremy D. Pavleck , Pavleck.NET
# DATE  : 12/14/2008
#
# COMMENT: Lists the percentage of battery remaining above your prompt inside the console.
#    Difficulty level: OVER 9000!!!!!!!!!!!!!!!!
#
# ==============================================================================================
$GLOBAL:BatteryDisplayAtPercent = 101 # When you should start displaying status
# Anything over 100 means to show it all
Function GLOBAL:Get-BattLevel($minLevel) {
$charge = (Get-WmiObject -Class Win32_Battery).EstimatedChargeRemaining
If(!$charge) {break} # Not on a laptop, or no battery, so exit
Switch($charge) {
{($charge -ge 101) -and ($minLevel -ge 101)} {Write-Host "Batt: CHARGING" -ForeGroundColor Green}
{($charge -ge 80) -and ($charge -le 100) -and ($charge -le $minLevel)} {Write-Host "Batt: $charge%" -ForeGroundColor Green}
{($charge -ge 40) -and ($charge -le 79) -and ($charge -le $minLevel)} {Write-Host "Batt: $charge%" -ForeGroundColor Yellow}
{($charge -ge 16) -and ($charge -le 39) -and ($charge -le $minLevel)} {Write-Host "Batt: $charge%" -ForeGroundColor Magenta}
{($charge -ge 1) -and ($charge -le 15) -and ($charge -le $minLevel)} {Write-Host "Batt: $charge%" -ForeGroundColor Red}
default {break}
}
}

function prompt() {
Get-BattLevel $GLOBAL:BatteryDisplayAtPercent
}

Categories: Powershell Tags: , ,

Reminder: System Center Virtual User Group Meeting 2, PowerScripting LIVE tonight

September 4th, 2008 jpavleck 2 comments

Two awesome events are happening tonight. I’ll be at both, come join me!

The first is the second meeting of the System Center Virtual User Group – Register to attend.
It begins 7pm CST (1am GMT) and the agenda is:
7:00PM-7:10PM: Introduction – Pete Zerger (Of SystemCenterForum.org)
7:10PM-7:40PM: Steve Rachui – Targeting in Operations Mananger 2007.
7:40PM-8:10PM: Cameron Fuller – Community Extensions for Operations Mananger 2007.
8:10PM-8:40PM: Pete Zerger – SNMP Device Monitoring in Operations Mananger 2007.
8.40PM-8:55PM: Closing – Pete Zerger

Logo for Google Calendar invite

The invitation has all the other information you need. This is a Live Meeting event, and dial in audio information is provided.

EDITED: Thanks for the additional info, Hal!

The second meeting happening today is episode 40 of the PowerScripting Podcast. This will also be the second (Or is it third?) time Hal and crew stream the show live!
If you can’t make it to the live UStream broadcast, be sure to subscribe to the podcast and get your weekly dose of PoShy goodness.
Along with the usual suspects of Hal, Joel and Jon, they have an extra-special guest this week; none other then the great Jeffrey Snover, one of the PowerShell architects. He’ll be taking your questions, so this would be a great time to ask about what’s new in v2, or why remote registry support sucks.

That all starts tonight at 9PM EST – so get your browsers ready to watch Hal and his beard. And if your place of work doesn’t block social networking sites, be sure to RSVP to the invite on FaceBook.

Logo for Google Calendar invite