How to Build a Custom WMI Asset Logger for Windows

Written by

in

Windows administrators often struggle to keep an accurate, automated inventory of hardware and software. Relying on heavy, expensive third-party tools is not always necessary. By utilizing Windows Management Instrumentation (WMI) and PowerShell, you can build a lightweight, customized asset logger tailored precisely to your organization’s needs. Why Build a Custom WMI Logger?

WMI is a built-in infrastructure that provides management data and operations on Windows operating systems. Querying WMI allows you to pull deep configuration data directly from the OS kernel and hardware components without installing external agents. Building your own tool offers several distinct advantages:

Zero Footprint: Uses native Windows tools already present on every machine.

Complete Customization: You decide exactly which data points to collect, omitting unnecessary clutter.

Cost-Effective: Avoids per-seat licensing fees associated with enterprise asset management suites.

Easy Automation: Scripts can easily be scheduled via Group Policy Objects (GPO) or Task Scheduler. Step 1: Identifying Key WMI Classes

WMI organizes data into classes. To build an effective asset logger, you need to know which classes hold the vital statistics of your workstation or server fleet. The most critical classes include:

Win32_ComputerSystem: Captures the manufacturer, model, total physical memory, and the logged-in user.

Win32_BIOS: Retrieves the serial number (Service Tag) and BIOS version.

Win32_OperatingSystem: Pulls the OS name, architecture (64-bit or 32-bit), version, and install date.

Win32_Processor: Provides details on the CPU model, core count, and current clock speed.

Win32_LogicalDisk: Inventories storage drive sizes and available free space. Step 2: Extracting Data via PowerShell

PowerShell features a built-in cmdlet, Get-CimInstance (which replaces the older Get-WmiObject), designed to safely and efficiently query WMI classes.

Here is how you can pull specific properties from a target machine and store them in variables: powershell

# Gather System and Hardware Details \(CompSystem = Get-CimInstance -ClassName Win32_ComputerSystem \)BIOS = Get-CimInstance -ClassName Win32_BIOS \(OS = Get-CimInstance -ClassName Win32_OperatingSystem \)CPU = Get-CimInstance -ClassName Win32_Processor \(Disk = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID='C:'" </code> Use code with caution. Step 3: Structuring the Asset Report</p> <p>Once the raw data is captured, it needs to be formatted into a clean, unified object. Creating a custom PowerShell object allows you to map the WMI outputs into readable property names. powershell</p> <p><code>\)AssetData = [PSCustomObject]@{ ComputerName = \(CompSystem.Name Manufacturer = \)CompSystem.Manufacturer Model = \(CompSystem.Model SerialNumber = \)BIOS.SerialNumber OS_Name = \(OS.Caption OS_Version = \)OS.Version CPU = \(CPU.Name RAM_GB = [Math]::Round(\)CompSystem.TotalPhysicalMemory / 1GB, 2) Disk_Size_GB = [Math]::Round(\(Disk.Size / 1GB, 2) Disk_Free_GB = [Math]::Round(\)Disk.FreeSpace / 1GB, 2) CurrentUser = \(CompSystem.UserName DateLogged = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss") } </code> Use code with caution. Step 4: Exporting to a Central Repository</p> <p>An asset logger is only useful if the data is aggregated in a central location. For small to medium networks, exporting the results to a shared network folder as a CSV file is the simplest method.</p> <p>By using the <code>-Append</code> flag, every machine on your network can write its configuration data to the exact same file, building a master inventory list over time. powershell</p> <p><code>\)NetworkPath = “\YourServer\AssetLogShare\(\NetworkAssets.csv" # Append data to the central CSV file \)AssetData | Export-Csv -Path \(NetworkPath -Append -NoTypeInformation </code> Use code with caution. Step 5: Automating the Deployment</p> <p>To ensure your asset log stays up to date, the script should run automatically across your domain.</p> <p><strong>Save the Script:</strong> Save your complete code as <code>AssetLogger.ps1</code> in a secure network location.</p> <p><strong>Configure a Group Policy Object (GPO):</strong> Create a new GPO in Active Directory named "Asset Logging Policy."</p> <p><strong>Set up a Startup Script:</strong> Navigate to <em>Computer Configuration > Policies > Windows Settings > Scripts (Startup/Shutdown) > Startup</em>.</p> <p><strong>Add the PowerShell Script:</strong> Point the startup sequence to your network-stored <code>.ps1</code> file.</p> <p>Every time a computer boots up on the domain, it will silently query its own WMI repository and append its latest configuration data to your central CSV file. Best Practices for Maintenance</p> <p>To keep your custom asset logger running smoothly, keep these operational tips in mind:</p> <p><strong>Manage Permissions:</strong> Ensure the hidden network share (<code>AssetLogShare\)) grants “Write” permissions to the “Domain Computers” group, but restricts “Read” permissions to Administrators to keep inventory data secure.

Network Reliability: Using Get-CimInstance locally on boot avoids the DCOM firewall issues commonly encountered when trying to scan remote machines over the network.

Scale to SQL: If your network grows beyond a few hundred devices, modify the export step of the script to send data directly to a SQL database using the Invoke-Sqlcmd cmdlet rather than writing to a single flat CSV file.

By spending just a few minutes configuring this native solution, you gain complete visibility over your IT infrastructure without introducing third-party overhead or security risks.

To tailor this script perfectly to your organization, let me know:

What specific hardware or software data points do you need to track?

Where do you plan to store the logged data (CSV, SQL database, or SharePoint)?

What version of Windows makes up the majority of your network?

I can help modify the script to meet your exact deployment requirements.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *