Automating BGInfo Deployment on Windows

Automating BGInfo Deployment on Windows

Keeping important system information visible on Windows desktops can make administration and troubleshooting easier. Sysinternals BGInfo can display that information on the desktop wallpaper, but deploying and maintaining it across multiple machines can take time.

This project automates that process with a single PowerShell script. It deploys BGInfo, its configuration and wallpaper, creates an all-users Startup shortcut, and applies the wallpaper immediately. The script is designed to be re-run safely whenever you need to refresh a deployment.

Windows Server desktop with a blue Windows-themed wallpaper
A Windows Server desktop with the custom wallpaper.

Explore the BGInfo Deployment repository or view the deployment script on GitHub. This post is based on the project’s README.

What the script does

  1. Acquires the BGInfo executable, configuration and wallpaper from the available sources.
  2. By default, compares local files against online sources using SHA-256 and replaces files when their contents differ. Online checking is skipped when a source share is supplied or -SkipOnlineUpdateCheck is used.
  3. Deploys the existing .bgi configuration without generating or modifying it.
  4. Ensures the wallpaper referenced by the configuration is available. If it is missing, the script logs a warning rather than stopping the deployment.
  5. Removes the legacy BgInfo registry Run value, if present, to avoid starting BGInfo twice.
  6. Creates or refreshes an all-users Startup shortcut so BGInfo runs at interactive logon.
  7. Runs BGInfo immediately for the current session.

Default paths

ItemDefault location
BGInfo executableC:\SysAdmin\Tools\SysinternalsSuite\Bginfo64.exe
Configuration fileC:\ProgramData\BGInfo\BGInfoStandard.bgi
Wallpaper imageC:\SysAdmin\Images\WindowsServer2028.jpg
Startup shortcutC:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\Bginfo64.exe.lnk

The shortcut launches BGInfo with the configuration and silent options:

Bginfo64.exe "C:\ProgramData\BGInfo\BGInfoStandard.bgi" /timer:0 /nolicprompt /silent

Where deployment files come from

The script checks sources in priority order for each file:

FileFirst choiceSecond choiceThird choice
Bginfo64.exe / Bginfo.exe-SourcePath file shareSysinternals BGInfo ZIP downloadGitHub repository
BGInfoStandard.bgi-SourcePath file shareExisting local copyGitHub repository
WindowsServer2028.jpg-SourcePath file shareExisting local copy / -WallpaperUrlGitHub repository
Startup shortcutAlways generated from scratch; never copied or downloaded

A supplied file share takes priority, but a partially stocked share can still be used: missing files produce a warning and the script falls through to other sources. The default online source is the companion GitHub repository. Its raw URLs point to the latest commit on main.

Downloads are staged in a temporary file before being moved into place. If an online update check fails, the existing local file is retained.

Running the deployment

Open PowerShell as an administrator and run the script. Here are some common examples:

# Standard run: check online sources for updates
.\DeployAndConfigureBgInfo.ps1

# Deploy from an internal file share
.\DeployAndConfigureBgInfo.ps1 -SourcePath '\\fileserver\Deploy\BGInfo'

# Skip online update checks
.\DeployAndConfigureBgInfo.ps1 -SkipOnlineUpdateCheck

# Register optional monthly maintenance
.\DeployAndConfigureBgInfo.ps1 -RegisterMonthlyTask

# Force a fresh BGInfo executable download
.\DeployAndConfigureBgInfo.ps1 -UpdateBgInfo

# Specify a custom wallpaper source
.\DeployAndConfigureBgInfo.ps1 -WallpaperUrl 'https://intranet.contoso.com/branding/WindowsServer2028.jpg'

# Use a share on an air-gapped machine
.\DeployAndConfigureBgInfo.ps1 -SourcePath '\\fileserver\Deploy\BGInfo' -OnlineSourceUrl ''

Available parameters

ParameterDefaultPurpose
-SourcePathNoneShare or folder containing deployment files; supplied files take priority.
-BgInfoExeC:\SysAdmin\Tools\SysinternalsSuite\Bginfo64.exeLocal executable path.
-BgInfoConfigC:\ProgramData\BGInfo\BGInfoStandard.bgiConfiguration used by the shortcut and immediate run.
-StartupShortcutAll-users Startup folderPath for the generated shortcut.
-WallpaperPathC:\SysAdmin\Images\WindowsServer2028.jpgLocal wallpaper path; it must match the path stored in the .bgi.
-WallpaperUrlNoneExplicit online wallpaper source, overriding the repository for this file.
-OnlineSourceUrlGitHub repository raw URL on mainOnline fallback base URL; set to an empty string to disable online fallbacks.
-BgInfoDownloadUrlSysinternals BGInfo ZIPPrimary download source for the executable.
-UpdateBgInfoOffRe-download the executable even if present, unless supplied by the share.
-SkipOnlineUpdateCheckOffSkip the per-run online SHA-256 comparison.
-RegisterMonthlyTaskOffRegister or refresh the optional monthly maintenance task.

Optional monthly maintenance

Use -RegisterMonthlyTask to create or refresh the BGInfo Monthly Maintenance scheduled task. It runs on the first day of each month at 03:00 under SYSTEM with highest privileges, re-running the script with default settings and appending output to DeployAndConfigureBgInfo.log next to the script.

The task is strictly opt-in: normal runs do not create or modify it. To remove it, run:

schtasks /Delete /TN "BGInfo Monthly Maintenance" /F

Design decisions

Startup shortcut instead of a registry Run entry

The all-users Startup shortcut is visible and self-documenting. The script removes the legacy registry value to prevent duplicate launches, and regenerates the shortcut on each run so it uses the configured local paths.

Deploy the BGInfo configuration unchanged

The .bgi file is a proprietary binary format, so editing it programmatically risks corruption. Instead, edit it in the BGInfo GUI, save it, publish it to the share or GitHub repository, and re-run the deployment script on target machines.

Match the wallpaper path

The .bgi references the wallpaper by an absolute local path. If you change that path in the configuration, supply a matching -WallpaperPath when running the script.

Testing and error handling

The README describes tested scenarios including local deployments, online downloads, fallback when Sysinternals is unavailable, an internal file share, stale local files, and runs with online update checking disabled.

The script provides timestamped, color-coded logs, a configuration banner and a deployment summary. Fatal errors terminate with exit code 1 for management tools to detect. Non-fatal issues, such as a missing wallpaper or failed online update check, are logged as warnings.

Requirements

  • Windows with PowerShell 5.1 or later.
  • Administrator rights.
  • TLS 1.2 capability, enabled by the script when needed.
  • Internet access when required files are not available locally or from the supplied share.

For the latest source and full details, visit the BGInfo Deployment repository on GitHub.

Az PowerShell Module Cleanup Script

Introduction

I have had some versions of my home-grown PowerShell script around to clean out the residues of obsolete Azure PowerShell modules from my workstations and laptops. Many of you know that those tend to accumulate over time. As a hobby project, I refined it to share with the world. You can find the script on my GitHub page WorkingHardInIT/AzurePowerShellModulesCleanUp: My Ultimate Azure PowerShell Module Cleanup Script

🔍 Az PowerShell Module Cleanup Script

A PowerShell utility for cleaning up old or duplicate versions of Azure PowerShell (Az) modules across Windows PowerShell and PowerShell Core. It ensures that only the latest version of each Az module is retained—keeping your environment clean, fast, and free from version conflicts.


⚙️ Features

  • ✅ Detects all installed Az and Az.* modules
  • 🧩 Groups by PowerShell edition and installation scope (CurrentUser vs AllUsers)
  • ⛔ Skips removal of AllUsers modules if not run as Administrator
  • 🔄 Keeps only the latest version of each module
  • 📋 Logs results to both Markdown and HTML
  • 🎨 Color-coded output with emoji support in PowerShell Core, fallback labels in Windows PowerShell

🧰 Requirements

  • PowerShell 5.1 (Windows PowerShell) or PowerShell Core (7+)
  • Administrator privileges (for full cleanup including AllUsers modules)
  • Az modules already installed via Install-Module

🛠️ Installation

Clone this repo or download the .ps1 script:

git clone https://github.com/yourusername/az-module-cleanup.git

Or simply download CleanupOldAzurePowerShellModulesWorkingHardInIT.ps1.


🚀 Usage

Run the script directly in a Windows Terminal PowerShell session:

.\CleanupOldAzurePowerShellModulesWorkingHardInIT.ps1

💡 If not run as Administrator, the script will prompt to elevate. If declined, only CurrentUser modules will be cleaned.
❗ If you don’t have Windows Terminal, get it or adapt the script to launch Powershell.exe or pwsh.exe directly


📝 Logs

After execution, logs are saved in the following directory:

<Script Directory>\AzModuleCleanupLogs\

Each run creates:

  • AzCleanup_<timestamp>.md – Markdown log (GitHub friendly)
  • AzCleanup_<timestamp>.html – HTML log (colored, styled)

📦 Example Output

🔍 Scanning for duplicate Az module versions by scope and edition...

📌 Az.Accounts (PowerShellCore in AllUsers):
🧩 Versions Installed: 3
❗ Versions to Remove: 2
📋 All Versions: 2.2.0, 2.1.0, 1.9.5

✅ Successfully uninstalled Az.Accounts version 2.1.0
✅ Successfully uninstalled Az.Accounts version 1.9.5

✅ Cleanup complete. Only the latest versions of Az modules are retained.

⚠️ Notes

  • Deletion of modules is attempted first via Uninstall-Module. If that fails, the script tries to remove directories manually.
  • To force elevation in PowerShell Core, wt.exe (Windows Terminal) is used to relaunch with admin rights.

📄 License

This project is licensed under the MIT License.


🙌 Credits

Crafted with care by Didier Van Hoye

Script to Bulk Invite Guest Users to Azure Entra ID

Introduction

Last week, I was on service desk duty. It’s not my favorite field of endeavour, and I’m past my due date for that kind of work. However, doing it once in a while is an eye-opener to how disorganized and chaotic many organizations are. Some requests are ideal to solve by automating them and handing them over to the team to leverage. That is how I wrote a script to bulk invite guest users to Azure Entra ID, as I could not bring myself to click through the same action dozens of times in the portal. You can find the script on my GitHub page https://github.com/WorkingHardInIT/BulkInviteGuestUsersToEntraIdAzure

Script to Bulk Invite Guest Users to Azure Entra ID

📌 Overview

This PowerShell script allows administrators to bulk invite guest users to an Azure Entra ID (formerly Azure Active Directory) tenant using Microsoft Graph. It includes retry logic for connecting to Microsoft Graph, supports both interactive and device code login, and reads user details from a CSV file.

✨ Features

  • Connects to Microsoft Graph securely using MS Graph PowerShell SDK
  • Retry logic with customizable attempt count
  • Supports both interactive and device-based authentication
  • Invites guest users based on a CSV file input
  • Allows optional CC recipients in the invitation email (limited to one due to API constraints)
  • Includes meaningful console output and error handling

📁 Prerequisites


📄 CSV File Format

Create a file named BulkInviteGuestUsersToAzureEntraID.csv in the same folder as the script with the following columns:

emailAddress,displayName,ccRecipients
[email protected],Guest One,[email protected]
[email protected],Guest Two,

Note: Only the first ccRecipient will be used due to a known Microsoft Graph API limitation.


🔧 Script Configuration

Open the script and configure the following variables:

$Scopes = "User.Invite.All" # Required scope
$csvFilePath = ".\BulkInviteGuestUsersToAzureEntraID.csv"
$TenantID = "<your-tenant-id-guid-here>" # Replace with your tenant ID
$emailAddresses = $Null # Optional static list of CC recipients

▶️ How to Run

  1. Open PowerShell as Administrator
  2. Install Microsoft Graph module (if not already):Install-Module Microsoft.Graph -Scope CurrentUser
  3. Execute the script:.\InviteGuestsToAzureEntraID.ps1Or specify login type:Test-GraphConnection -TenantID “<tenant-id>” -Scopes $Scopes -UseDeviceLogin

🧠 Function: Test-GraphConnection

This helper function ensures a valid Microsoft Graph session is established:

  • Disconnects any stale Graph sessions
  • Attempts up to $MaxRetries times to connect
  • Verifies that the session is for the specified Tenant ID
  • Supports -UseDeviceLogin switch for non-interactive login (e.g., headless servers)

📬 Inviting Users

The script loops through all entries in the CSV file and sends out personalized invitations using the New-MgInvitation cmdlet.

Each invite includes:

  • Redirect URL (https://mycompany.portal.com)
  • Display name from CSV
  • Custom message
  • Optional CC recipient (only first address is respected by Graph API)

⚠️ Known Issues

  • CC Recipients Limitation: Only the first email in ccRecipients is honored. This is a known issue in the Microsoft Graph API.
  • Multi-user CC: If different users need unique CCs, adapt the script to parse a ccRecipients column with user-specific values.

📤 Example Output

✅ Using device login for Microsoft Graph...
✅ Microsoft Graph is connected to the correct Azure tenant (xxxx-xxxx-xxxx).
✅ Invitation sent to Guest One using [email protected]
⚠️  Skipped a user due to missing email address.
⚠️  Failed to invite Guest Two: Insufficient privileges to complete the operation

🧽 Cleanup / Disconnect

Graph sessions are managed per execution. If needed, manually disconnect with:

Disconnect-MgGraph

📚 References


🛡️ License

This script is provided as-is without warranty. Use it at your own risk. Feel free to adapt and extend as needed.


✍️ Author

Didier Van Hoye

Contributions welcome!

Connect to an Azure VM via Bastion with native RDP using only Azure PowerShell

Connect to an Azure VM via Bastion with native RDP using only Azure PowerShell

To connect to an Azure VM via Bastion with native RDP using only RDP requires a custom solution. By default, the user must leverage Azure CLI. It also requires the user to know the Bastion subscription and the resource ID of the virtual machine. That’s all fine for an IT Pro or developer, but it is a bit much to handle for a knowledge worker.

That is why I wanted to automate things for those users and hide that complexity away from the users. One requirement was to ensure the solution would work on a Windows Client on which the user has no administrative rights. So that is why, for those use cases, I wrote a PowerShell script that takes care of everything for an end user. Hence, we chose to leverage the Azure PowerShell modules. These can be installed for the current user without administrative rights if needed. Great idea, but that left us with two challenges to deal with. These I will discuss below.

A custom PowerShell Script

The user must have the right to connect to their Virtual Machine in Azure over the (central) bastion deployment. These are listed below. See Connect to a VM using Bastion – Windows native client for more information.

  • Reader role on the virtual machine.
  • Reader role on the NIC with private IP of the virtual machine.
  • Reader role on the Azure Bastion resource.
  • Optionally, the Virtual Machine Administrator Login or Virtual Machine User Login role

When this is OK, this script generates an RDP file for them on the desktop. That script also launches the RDP session for them, to which they need to authenticate via Azure MFA to the Bastion host and via their VM credentials to the virtual machine. The script removes the RDP files after they close the RDP session. The complete sample code can be found here on GitHub.

I don’t want to rely on Azure CLI

Microsoft uses Azure CLI to connect to an Azure VM via Bastion with native RDP. We do not control what gets installed on those clients. If an installation requires administrative rights, that can be an issue. There are tricks with Python to get Azure CLI installed for a user, but again, we are dealing with no technical profiles here.

So, is there a way to get around the requirement to use Azure CLI? Yes, there is! Let’s dive into the AZ CLI code and see what they do there. As it turns out, it is all Python! We need to dive into the extension for Bastion, and after sniffing around and wrapping my brain around it, I conclude that these lines contain the magic needed to create a PowerShell-only solution.

See for yourself overhere: azure-cli-extensions/src/bastion/azext_bastion/custom.py at d3bc6dc03bb8e9d42df8c70334b2d7e9a2e38db0 · Azure/azure-cli-extensions · GitHub

In PowerShell, that translates into the code below. One thing to note is that if this code is to work with PowerShell for Windows, we cannot use “keep-alive” for the connection setting. PowerShell core does support this setting. The latter is not installed by default.

# Connect & authenticate to the correct tenant and to the Bastion subscription
Connect-AzAccount -Tenant $TenantId -Subscription $BastionSubscriptionId | Out-Null

 #Grab the Azure Access token
    $AccessToken = (Get-AzAccessToken).Token
    If (!([string]::IsNullOrEmpty($AccessToken))) {
        #Grab your centralized bastion host
        try {
            $Bastion = Get-AzBastion -ResourceGroupName $BastionResoureGroup -Name $BastionHostName
            if ($Null -ne $Bastion ) {
                write-host -ForegroundColor Cyan "Connected to Bastion $($Bastion.Name)"
                write-host -ForegroundColor yellow "Generating RDP file for you to desktop..."
                $target_resource_id = $VmResourceId
                $enable_mfa = "true" #"true"
                $bastion_endpoint = $Bastion.DnsName
                $resource_port = "3389"

                $url = "https://$($bastion_endpoint)/api/rdpfile?resourceId=$($target_resource_id)&format=rdp&rdpport=$($resource_port)&enablerdsaad=$($enable_mfa)"

                $headers = @{
                    "Authorization"   = "Bearer $($AccessToken)"
                    "Accept"          = "*/*"
                    "Accept-Encoding" = "gzip, deflate, br"
                    #"Connection" = "keep-alive" #keep-alive and close not supported with PoSh 5.1 
                    "Content-Type"    = "application/json"
                }

                $DesktopPath = [Environment]::GetFolderPath("Desktop")
                $DateStamp = Get-Date -Format yyyy-MM-dd
                $TimeStamp = Get-Date -Format HHmmss
                $DateAndTimeStamp = $DateStamp + '@' + $TimeStamp 
                $RdpPathAndFileName = "$DesktopPath\$AzureVmName-$DateAndTimeStamp.rdp"
                $progressPreference = 'SilentlyContinue'
            }
            else {
                write-host -ForegroundColor Red  "We could not connect to the Azure bastion host"
            }
        }
        catch {
            <#Do this if a terminating exception happens#>
        }
        finally {
            <#Do this after the try block regardless of whether an exception occurred or not#>
        }

Finding the resource id for the Azure VM by looping through subscriptions is slow

As I build a solution for a Windows client, I am not considering leveraging a tunnel connection (see Connect to a VM using Bastion – Windows native client). I “merely” want to create a functional RDP file the user can leverage to connect to an Azure VM via Bastion with native RDP.

Therefore, to make life as easy as possible for the user, we want to hide any complexity for them as much as possible. Hence, I can only expect them to know the virtual machine’s name in Azure. And if required, we can even put that in the script for them.

But no matter what, we need to find the virtual machine’s resource ID.

Azure Graph to the rescue! We can leverage the code below, and even when you have to search in hundreds of subscriptions, it is way more performant than Azure PowerShell’s Get-AzureVM, which needs to loop through all subscriptions. This leads to less waiting and a better experience for your users. The Az.ResourceGraph module can also be installed without administrative rights for the current users.

$VMToConnectTo = Search-AzGraph -Query "Resources | where type == 'microsoft.compute/virtualmachines' and name == '$AzureVmName'" -UseTenantScope

Note using -UseTenantScope, which ensures we search the entire tenant even if some filtering occurs.

Creating the RDP file to connect to an Azure Virtual Machine over the bastion host

Next, I create the RDP file via a web request, which writes the result to a file on the desktop from where we launch it, and the user can authenticate to the bastion host (with MFA) and then to the virtual machine with the appropriate credentials.

        try {
            $progressPreference =  'SilentlyContinue'
            Invoke-WebRequest $url -Method Get -Headers $headers -OutFile $RdpPathAndFileName -UseBasicParsing
            $progressPreference =  'Continue'

            if (Test-Path $RdpPathAndFileName -PathType leaf) {
                Start-Process $RdpPathAndFileName -Wait
                write-host -ForegroundColor magenta  "Deleting the RDP file after use."
                Remove-Item $RdpPathAndFileName
                write-host -ForegroundColor magenta  "Deleted $RdpPathAndFileName."
            }
            else {
                write-host -ForegroundColor Red  "The RDP file was not found on your desktop and, hence, could not be deleted."
            }
        }
        catch {
            write-host -ForegroundColor Red  "An error occurred during the creation of the RDP file."
            $Error[0]
        }
        finally {
            $progressPreference = 'Continue'
        }

Finally, when the user is done, the file is deleted. A new one will be created the next time the script is run. This protects against stale tokens and such.

Pretty it up for the user

I create a shortcut and rename it to something sensible for the user. Next, I changed the icon to the provided one, which helps visually identify the shortcut from any other Powershell script shortcut. They can copy that shortcut wherever suits them or pin it to the taskbar.

Connect to an Azure VM via native RDP using only Azure PowerShell