Script: Create live tiles that changes power scheme

After i got my Surface Pro, I’ve more often than before found myself needing to change between power schemes. On my laptop, I’ll usually set it to “Max performance” and just leave it there, but on the Surface it’s necessary to conserve power a bit more.

I’ve thought about making a live tile to do this, so I wrote a PowerShell script that will create one live tile for each configured powerscheme on the machine and pins it to the start screen. The code is based on a codesample for creating shutdown tiles, and this ScriptingGuy post. The script needs to be run as Administrator. Enjoy!

Download Create-PowerSchemeTiles.zip or copy the sourcecode:


#requires -Version 3.0

#####################################################################################
# Create-PowerSchemeTiles.ps1
#
# Creates live tiles for all configured power schemes on the machine and pins them to
# the start screen.
#
#
# Usage:
# .Create-PowerSchemeTiles.ps1
#
# Written by Tom-Inge Larsen (<a href="http://www.codesalot.com">http://www.codesalot.com</a>)
#
#####################################################################################

Function CreatePowerSchemeTile
{
    Param
    (
        [parameter(Mandatory=$true)][String[]]$SchemeGUID,
        [parameter(Mandatory=$true)][String[]]$SchemeName
    )
Write-Verbose "Creating Windows shutdown tile to Start menu."

#create a new shortcut
$ShortcutPath = "$env:ProgramData\Microsoft\Windows\Start Menu\Programs\" + $SchemeName + ".lnk"
$Shortcut = $WshShell.CreateShortcut($ShortcutPath)
$Shortcut.TargetPath = "$env:SystemRoot\System32\powercfg.exe"
$arguments = "-s " + $SchemeGUID
$Shortcut.Arguments = $arguments
$Shortcut.Save()

#change the default icon of shortcut
$Lnk = $Desktop.ParseName($ShortcutPath)
$LnkPath = $Lnk.GetLink
$LnkPath.SetIconLocation("$env:SystemRoot\System32\ddores.dll",20)
$LnkPath.Save()

#pin application to windows Start menu
$Verbs = $Lnk.Verbs()
Foreach($Verb in $Verbs) {
    If($Verb.Name.Replace("&","") -match "Pin to Start") {
        $Verb.DoIt()
    }
}

If(Test-Path -Path $ShortcutPath) {
    Write-Host "Create" $SchemeName "tile successfully." -ForegroundColor Green
    } Else {
    Write-Host "Failed to create" $SchemeName "tile." -ForegroundColor Red
   }
}

$Shell = New-Object -ComObject Shell.Application
$Desktop = $Shell.NameSpace(0X0)
$WshShell = New-Object -comObject WScript.Shell
$plans = Get-WmiObject -Class win32_powerplan -Namespace root\cimv2\power
$regex = [regex]"{(.*?)}$"
foreach ($plan in $plans) {
    $planGuid = $regex.Match($plan.instanceID.Tostring()).groups[1].value
    $planName = $plan.ElementName.Tostring()
    Write-Debug $planGuid
    Write-Debug $planName
    CreatePowerSchemeTile -SchemeGUID $planGuid -SchemeName $planName
}

Surface Pro and scaling and fuzzy looking desktop apps

After a bit of chasing around San Diego last week during Lyncconf13, I was able to get a hold of a 128GB Surface Pro at the Best Buy in Fashion Valley, and I absolutely love it so far.  The screen is very good and responsive and the Pen is the best stylus I have tried so far. Makes taking notes in OneNote a blast!

But one of the small things that has bugged me a bit is that some desktop programs seem a bit fuzzy, like for instance Spotify and Chrome (Everyone needs a second browser right?) Some of them are also hard to use with your fingers, I had to use the Pen in Chrome for instance. This happens because the Surface is by default set to scale the desktop to 125%, and those apps aren’t handling that. (I’ve seen that some say the surface is scaled to 150%, but mine was/is not. The result should be the same though)

You can resolve this by telling windows not to scale those programs, like I’ve shown below. (Spotify screens are thumbnailed, click them to se full size.)

I’ll be going back to playing with my Surface now!

This is what Spotify looked like before
This is what Spotify looked like before
Right click twice and choose properties
Right click twice and choose properties
On the Compatability tab, check the "Disable display scaling on high DPI settings" option
On the Compatability tab, check the “Disable display scaling on high DPI settings” option

And the result looks much better!
And the result looks much better!