O/S Configurations from SQL Server

The T-SQL code snippet belows returns details regarding the Operating System using the NETSH utility. The details returned range from the Windows Directory to the Service Pack Version and everything in between.

CREATE TABLE #os
(
token NVARCHAR(100) NULL
)

INSERT INTO #os (token)
EXEC   master.dbo.xp_cmdshell ‘netsh diag SHOW os /p’

SELECT  LTRIM(SUBSTRING(token, 1, CHARINDEX(‘=’, token)-1)) AS property,
SUBSTRING(token, CHARINDEX(‘=’, token)+1, 100) AS value
FROM  #os
WHERE  token LIKE ‘%=%’

DROP TABLE #os