Tatoo the Background of your Virtual Machines

You may know the popular Bginfo from Sysinternals and that even Azure uses this utility to tatoo the background of virtual machines.

I wondered if PowerShell (alone) would make it and avoid the dependency on an external binary.

I started to use Google and finally decided to fork the following code available on github: https://github.com/fabriceleal/Imagify/blob/master/imagify.ps1

I also needed to find the way to set a wallpaper under Windows 7 and later…
I decided to extend this PowerTip: http://powershell.com/cs/blogs/tips/archive/2014/01/10/change-desktop-wallpaper.aspx because the rundll32 tricks doesn’t work.

I created two functions, one to create a new background image either from scratch and based on a colored theme (blue, grey and black) or from the existing wallpaper and the second one to set this image as a wallpaper.

Let’s see these two functions in action.

First define some multiline text to be written in the image.

    • Exemple 1: ala Backinfo
1
2
$WallPaper = New-BGinfo -text $t
Set-Wallpaper -Path $WallPaper.FullName -Style Center

    • Exemple 2: ala Bginfo using the current wallpaper
1
2
3
4
5
6
7
8
9
10
11
$BGHT = @{
 Text  = $t ;
 Theme = "Black" ;
 FontName = "Verdana" ;
 UseCurrentWallpaperAsSource = $true ;
}
$WallPaper = New-BGinfo @BGHT
Set-Wallpaper -Path $WallPaper.FullName -Style Fill
# Restore the default VM wallpaper
Set-Wallpaper -Path "C:\Windows\Web\Wallpaper\Windows\img0.jpg" -Style Fill

This proof of concept based on just a few hundred lines of PowerShell proves that the dependency on Bginfo could be avoided…