Skip to main content

One of the client recently requested me to help them find the duplicate bios uuid for their environment of 10K desktops, therefore, i am writing this post to help others if they are facing  same issues with duplicate bios uuid.

BIOS UUIDs are important identifiers that help distinguish one computer from another. They are typically unique, allowing administrators to manage their systems efficiently. However, in some cases, duplicate UUIDs might exist, causing confusion and possible errors. In this blog post, we'll show you how to create a PowerShell script that detects duplicate BIOS UUIDs on Windows computers and exports the results to an Excel file for further analysis.

Step 1: Creating the PowerShell Script

First, let's create a PowerShell script that queries a list of computers, retrieves their BIOS UUIDs, and checks for duplicates. You can get the list of computers from Active Directory, a text file, or an array.

Here's a sample script that demonstrates these steps:
 

# Import the Active Directory module (Optional)
# Import-Module ActiveDirectory

# Get the list of computer names
# $computers = Get-ADComputer -Filter * | Select-Object -ExpandProperty Name
# Alternatively, use a list of computer names from a text file or an array
$computers = Get-Content "computer_names.txt"

$uuidHashTable = @{}

foreach ($computer in $computers) {
try {
$bios = Get-WmiObject -Class Win32_ComputerSystemProduct -ComputerName $computer -ErrorAction Stop
$uuid = $bios.UUID

if ($uuidHashTable.ContainsKey($uuid)) {
$uuidHashTablel$uuid] += ", $computer"
} else {
$uuidHashTablel$uuid] = $computer
}
} catch {
Write-Warning "Failed to query BIOS UUID for $computer. Error: $_"
}
}

$dupUUIDs = $uuidHashTable.Keys | Where-Object { ($uuidHashTablel$_].Split(',')).Count -gt 1 }

if ($dupUUIDs.Count -gt 0) {
Write-Host "Duplicate BIOS UUIDs found:"
foreach ($uuid in $dupUUIDs) {
Write-Host "UUID: $uuid, Computers: $($uuidHashTablel$uuid])"
}
} else {
Write-Host "No duplicate BIOS UUIDs found."
}

Step 2: Exporting the Results to Excel

To export the results to an Excel file, you can use the ImportExcel PowerShell module. First, install the module if you haven't already:

Install-Module -Name ImportExcel -Scope CurrentUser

Next, modify the script to store the results in an Excel file:

# Import the necessary modules
# Import-Module ActiveDirectory
Import-Module ImportExcel

# ... .rest of the script]

if ($dupUUIDs.Count -gt 0) {
Write-Host "Duplicate BIOS UUIDs found:"
$results = @()
foreach ($uuid in $dupUUIDs) {
Write-Host "UUID: $uuid, Computers: $($uuidHashTablel$uuid])"
$results += =PSCustomObject]@{
UUID = $uuid
Computers = $uuidHashTablel$uuid]
}
}

# Export the results to an Excel file
$results | Export-Excel -Path "Duplicate_UUIDs.xlsx" -WorksheetName "Duplicates" -AutoSize -FreezeTopRow -AutoFilter -BoldTopRow

Write-Host "Results saved to Duplicate_UUIDs.xlsx"
} else {
Write-Host "No duplicate BIOS UUIDs found."
}

This modified script saves the duplicate BIOS UUIDs to an Excel file called "Duplicate_UUIDs.xlsx" in the current directory.

 

Love seeing scripts like this that can help the wider community. Thanks for sharing.


Thank you Chris.


If I had a dime for every time I had a client that was cloning VM’s or deploying workstations from images and didn’t know about sysprep, I’d have...like three dimes, and two of them are due to WSUS deployments.  Thanks for this info.


Comment