Configure BGInfo based on OU location

This is my way of automation to configure BGInfo on a server based on where in AD the server is located.

I have a customer where we need to deploy BGInfo with a background that informs the user logged on which Environment the server are connected to (Production, Acceptance, Test or Tier-0) and by using the computername and do a query to the AD to get the OU path for the server it runs the bginfo with the correct configfile for BGInfo.

By doing this i now have one package that i can deploy to one collection and leave it to the script to set the correct backgound after logon for the user.

But before you can use the script you need configure manually BGInfo with company logo, background pictures and choose colors and save a configfile for each environment. All files need to be saved in the same folder as the script.

At the end you will find Deploy-Application.ps1 used in AppDeploy Toolkit which i used in deploying it in MEMCM.


In my test-environment i have the following structure.

My BGInfo-folder are in the root of C: and it contains the followling files

  • Bginfo64.exe – Exe-file downloaded from (Please use 64bit version)
  • bginfoAcc.bgi – Configfile for BGInfo for servers in OU named Acceptance
  • bginfoProd.bgi – Configfile for BGInfo for servers in OU named Production
  • bginfoTest.bgi – Configfile for BGInfo for servers in OU named Test
  • bginfoTier.bgi – Configfile for BGInfo for servers in OU named Tier
  • bginfo.bmp – Picture generated by BGInfo
  • Acceptance.jpg – Backgroundpicture for servers in OU named Acceptance
  • Production.jpg – Backgroundpicture for servers in OU named Producution
  • Test.jpg – Backupgroundpicture for servers in OU named Test
  • Tier.jpg – Backgroundpicture for servers in OU named Tier
  • BGinfo.log – Logfile for the script, can be placed where ever you want – Settings in script
  • Run.bat – Bat-file that runs the script on logon. Script generated.
  • Set-BGInfo.ps1 – The script
  • BGInfo.xml – XML file that holds which OU should have which configurationfile

Check the AD

In the script a have the following part that get the computername and extract the OUpath and by filter the result you will get a searchable string to compare with the xml-file.

Note: This part of the script is not created by me…It´s created by a friend of mine who has expert knowledge in powershell 🙂

The result in the logfile:

The XML-file

The XML-file holds info about which OU should have which Configfile.

When the scripts compares $OUpath with XML-file with the following script part

The logfile register the following result after having the server in a OU called Production.

The bat-file & Registry run

I had some problem to run only the powershellscript on logon and had to use Run.bat instead. To automate this i had to generate the correct Run.bat based on where you install your BGInfo configuration

The following script part generate the Run.bat and save it in the same folder as the script it also add the path to Run.bat to the registry so it runs every time a user logon the server.

The batfile the runs everytime a user logon the server looks like this:

The script Set-BGInfo.ps1 Complete

I attach the script here for you to study…

Howto deploy it…MEMCM or Manually

It´s up to you how you want to deploy it.

If you want to deploy it manually to a server you need to copy the files to a folder on the server and run the “-Firstrun” parameter in the script.

If you want to deploy it with MEMCM and you are familiar with AppDeploy Toolkit (Website) you will find my Deploy-Application.ps1 at my Github in the same folder as the script or copy it from here:

There are two things you have to add or create in your deployment if you don´t use the scripts parameter “Firstrun”

  • Create a Run.bat file manually
  • Add run.bat in the registry to run at logon by user

Add a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Damberg Online

Subscribe now to keep reading and get access to the full archive.

Continue reading