DBA Scripts: Get OS and Hardware Info

🔧Part of the DBA-Tools Project, copy/paste SQL Server scripts and health checks.In: Server & ConfigurationServer Inventory

What Is This Server Actually Running On

Before you can reason about performance, capacity, or whether a setting makes sense, you need the basics: how much CPU and memory the box actually has, what OS it’s running, and how long SQL Server has been up. It’s a small set of facts, but it’s the context every other diagnostic script assumes you already know.

This script returns all of it in one row: SQL Server edition and version, Windows release, logical and physical CPU counts, physical memory, and uptime, everything you’d otherwise have to gather from three or four different places.


Why OS and Hardware Info Matters

  • Logical vs physical CPU count tells you whether hyperthreading is in play, which matters when comparing this server’s core count against licensing or against another server’s specs
  • Physical memory is the ceiling every other memory setting (max server memory, buffer pool) has to respect, you can’t reason about memory configuration without knowing the real number
  • sql_committed_mb next to physical_memory_gb gives a quick sanity check on how much of the box’s memory SQL Server is actually using right now
  • Uptime matters for more than trivia, a recent restart can explain a suddenly-empty plan cache, a cleared buffer pool, or wait statistics that look artificially low

When to Run This Script

  • First thing when inheriting or reviewing an unfamiliar server
  • Before making any memory or CPU-related configuration change, to know the real ceiling you’re working within
  • When something looks different than expected and you want to rule out a recent restart as the explanation
  • As part of a routine health check, alongside other inventory scripts in this series

The Script

Run the following script against your SQL Server instance.

✓ Verified
  • Tested on: SQL Server 2025 (RTM CU5), Windows lab instance
  • Last verified: 2026-08-07 (saved output from a real run, Get-OsAndHardwareInfo-20260807-211444.csv)
  • Permissions: VIEW SERVER STATE
  • Safety: read-only, impact low
Any thresholds in this script are operational heuristics; claim types are labelled where they appear in the text.
/*
Script Name : Get-OsAndHardwareInfo
Category    : configuration-and-environment
Purpose     : Show OS version, hardware specs (CPU, RAM), and SQL Server uptime in one row.
Author      : Peter Whyte (https://sqldba.blog/dba-scripts-get-os-and-hardware-info/)
Requires    : VIEW SERVER STATE
HealthCheck : Yes
*/
-- SAFE:ReadOnly
-- IMPACT:Low
SET NOCOUNT ON;

SELECT
    SERVERPROPERTY('MachineName') AS machine_name,
    SERVERPROPERTY('ServerName') AS server_name,
    SERVERPROPERTY('Edition') AS sql_edition,
    SERVERPROPERTY('ProductVersion') AS sql_version,
    SERVERPROPERTY('ProductLevel') AS sql_product_level,
    SERVERPROPERTY('ProductUpdateLevel') AS sql_cu_level,
    SERVERPROPERTY('IsClustered') AS is_clustered,
    wni.windows_release AS os_release,
    wni.windows_service_pack_level AS os_service_pack,
    wni.windows_sku AS os_sku,
    osi.cpu_count AS logical_cpu_count,
    osi.hyperthread_ratio AS hyperthread_ratio,
    osi.cpu_count / osi.hyperthread_ratio AS physical_cpu_count,
    CAST(osi.physical_memory_kb / 1024.0 / 1024 AS DECIMAL(10,2)) AS physical_memory_gb,
    CAST(osi.committed_kb / 1024.0 AS DECIMAL(12,2)) AS sql_committed_mb,
    osi.sqlserver_start_time AS sql_start_time,
    DATEDIFF(DAY, osi.sqlserver_start_time, GETDATE()) AS uptime_days,
    DATEDIFF(HOUR, osi.sqlserver_start_time, GETDATE()) % 24 AS uptime_hours_remainder
FROM sys.dm_os_sys_info AS osi
CROSS JOIN sys.dm_os_windows_info AS wni;

Everything comes from two DMVs joined with no filters, sys.dm_os_sys_info for hardware and uptime, sys.dm_os_windows_info for the OS details, both return exactly one row.


How To Run From The Repo

Clone DBA Tools, initialize and run the script:

# Clone dba-tools repo:
git clone https://github.com/peterwhyte-lgtm/dba-tools

# Initialize environment:
cd dba-tools
.\Initialize-Environment.ps1

# Get OS, hardware, and uptime in one row:
.\run.ps1 Get-OsAndHardwareInfo

# To run against a remote sql server:
.\run.ps1 Get-OsAndHardwareInfo -ServerInstance SQLSERVER01

This script lives in the repo at:


Example Output

One row, describing the whole instance: what it is running on, what hardware is underneath it, and how long it has been up.

Get-OsAndHardwareInfo output in SSMS: SQL Server edition, build 17.0.4075.5 RTM CU8, Windows release and CPU counts


Understanding the Results

machine_name
server_name
The Windows machine name and the SQL Server instance name. They differ on a clustered instance or a named instance, which is exactly when knowing both matters.
sql_edition
sql_version
sql_product_level
sql_cu_level
Edition, four-part build, servicing baseline and the CU on top of it. Patch Level is the script that exists to answer the currency question properly.
is_clustered
Whether the instance is running under a Windows failover cluster. It changes what a restart means and who else may have moved it.
os_release
os_service_pack
os_sku
The Windows version behind the instance. os_sku is a numeric Windows edition code rather than a name, so it needs looking up against Microsoft’s SKU list if the edition itself is the question.
logical_cpu_count
hyperthread_ratio
physical_cpu_count
physical_cpu_count is derived, not measured: the script divides logical_cpu_count by hyperthread_ratio, which gives the number of processor sockets. A VM reporting 8 logical with a ratio of 8 lands on 1, and that is a single socket rather than proof of anything about hyperthreading.Act when you are sizing MAXDOP or counting licences off these numbers. Take the topology from MAXDOP Configuration, which computes the recommendation from the same figures rather than leaving you to.
physical_memory_gb
sql_committed_mb
The hardware ceiling, and what SQL Server has actually committed right now. Read the second against configured max server memory rather than against the first: the gap you care about is what SQL Server was allowed, not what the box has.Act when committed memory sits close to the physical ceiling. Pair it with Recent Error Log Entries, because genuine memory pressure announces itself in the error log before it shows up here.
sql_start_time
uptime_days
uptime_hours_remainder
This is SQL Server uptime, not machine uptime, taken from the service start time. On a page titled OS and hardware that is an easy misread.Act when the uptime is short. An empty plan cache, a cold buffer pool and wait statistics that have barely accumulated all follow from it, and every cumulative counter on the instance is reading low for the same reason.

Microsoft’s reference covers sys.dm_os_sys_info in full.


Related Scripts

You may also find these scripts useful:


Frequently Asked Questions

Why does hyperthread_ratio show 1 with no hyperthreading?

hyperthread_ratio is the ratio of logical to physical schedulers, 1 means each logical CPU maps to its own physical core, no hyperthreading in effect. A value of 2 would mean each physical core presents two logical CPUs.

Does this replace Task Manager or Windows System Information?

Not entirely, this is SQL Server’s own view of the hardware, useful specifically because it’s queryable, scriptable, and captures what SQL Server itself sees, which can differ from raw OS-reported specs in a virtualized or containerized environment.


Summary

Hardware and OS context is the baseline every other diagnostic assumes, memory settings, CPU-related waits, and uptime-sensitive findings all need to be read against these numbers, not in isolation.

Run this first when reviewing any unfamiliar server, and keep it in mind whenever uptime is short enough that other diagnostics might just be reflecting a cold start rather than a real trend.

Comments

Leave a Reply

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