Recently I have been building a lot of Windows Servers in different environments - one of the things I used to love to install as a system administrator was BGINFO. This helped me keep track of which server I was on. BGINFO was a stable tool for any system I built and administered for quite a while
It would, as you expect, put information on the desktop image - this was very useful - made me less prone to mistakes. Mistakes make GrumpyAdmin very grumpy, and in my company, if people make a stupid mistake - they are Pizza Fined, which means they have to buy Pizza for the team! There is a reason; I am poor, overweight and looking at needing a heart bypass in the near future!!!
BGINFO helped ground an administrator into which system/server they were on!
However, BGINFO, an attack vector for particular environments, was banned and removed. MS has resolved the issues and is now safe and part of the Powertoys from Microsoft - However, it has now been delisted in most workplaces and environments I deal with.
Naturally, many replacements can be used - but the grumpy admin like to do his own thing and stuff and likes Powershell, and he thought to himself - can I do this in Powershell?
As I get easily distracted at work, I created a BGINFO PowerShell-type script.
I thought about it and the logical steps that I needed to take:
Get the information into variables - what variables would I want to get?, well things I feel are essential to know at a glance on a server is:
Hostname The Operating System The processor Total Memory in GB The IP address System UPTIME The domain name The current logon user Windows Defender last updated
Now as a PowerShell guru, we know how to collect these things.
Wow that works - So now I have this - I need a way for PowerShell to modify the desktop background.
This is where we can look at and use the C# abilities of Powershell.
So as you can see, there are lots of capabilities to manipulate graphics - looking at the table of classes - there is something we can use to achieve our aim!
DRAWSTRING
Now that I know that, I can start to create a function that will open an image file and then write the strings from the variables on the image.
After some trial and error work, I developed the following code.
Wow, that works! Amazing!
This proves the concept will work! So the next step is to get the code to write every variable on the desktop image!
Typically when dealing with Powershell and variables - it is much better to create what they call a HashMap
So here is a simple HashMap for my variables
Then we need to loop through the Hashmap and put them on JPG image.
So this part of the problem is sorted - we can generate a JPG image with our variable information printed on it!
The next thing to do is to set that as the active background image.
Here is a quick Google, and I find some sample code that does the trick - why reinvent the wheel? Grumpy Admin does something very common: Swipping with Pride - I am not the smartest of the best in the world, why trouble myself with writing and figuring stuff out when you can Google and swipe with pride? :)
The main thing is that as long as you understand what the code you steal does and that you don't violate any licences, you are golden!
Combine the whole thing, and I have a working prototype PowerShell code! Yippy!
Now as always, I have a working code example. It is time to turn that into a total production standard code!
There are many function templates, and the standard is well documented - so if you are doing POSH code much, you should know this. I am going to call this function - using the standard verb method.
Add-TextToImage
So variables are extracted, and a CmdLetBinding is created for each.
I used If statements used to toggle elements of the code on or off Added comments to the code at various structural points