"xp_cmdshell" is an extended stored procedure provided by Microsoft and stored in the master database. This procedure allows you to issue operating system commands directly to the Windows command shell via T-SQL code.
— To allow advanced options to be changed.
EXEC sp_configure ‘show advanced options’, 1;
— To update the currently configured value for advanced options.
— To enable the feature.
EXEC sp_configure ‘xp_cmdshell’, 1;
— To update the currently configured value for this feature.
Let’s start out with a simple directory search example. Say you do not have access to the physical SQL Server machine, but you want to see all the files are accessible form the database service. To do that enter the below command with the original path of the share path
Exec xp_cmdshell ‘Dir \\MyServer\MyShare\’