Home > SQL Server, SQL Server 2017 > sys.dm_os_host_info–DMV to find Operating System Information in SQL Server 2017

sys.dm_os_host_info–DMV to find Operating System Information in SQL Server 2017


SQL Server 2017 includes a new DMV to find Operating System information

sys.dm_os_host_info

 

SELECT host_platform,
host_distribution,
host_release,
host_service_pack_level,
host_sku,
os_language_version
FROM   sys.dm_os_host_info
 

Output from Windows Server

capture20171016105801406

Output from Ubuntu Linux Server

capture20171016105834926

This DMV will come in handy when writing maintenance scripts based on Operating System ex. Backup Script to get custom backup path based on OS

DECLARE @BackupPath VARCHAR(500)
DECLARE @OSInfo NVARCHAR(256)

SELECT @OSInfo = host_platform
FROM   sys.dm_os_host_info

IF @OSInfo = ‘Windows’
BEGIN
SET @BackupPath = ‘E:\SQLBackup\’
END
ELSE IF @OSInfo = ‘Linux’
BEGIN
SET @BackupPath = ‘/var/opt/BACKUP/’
END

SELECT @BackupPath [Backup Path] 

 

Output from Windows Server

capture20171016111911787

 

Output from Ubuntu Linux Server             

capture20171016111923741

Hope you find this post helpful !!!

 

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: