xp_cmdshell – How to Enable cmdshell in SQL Server?

xp_cmdshell is a very powerful procedure that allows you to execute commands via the command-line (cmd) in SQL Server. With cmdshell, you can perform various operations on a Windows server through the SQL platform, such as copying files, creating, deleting, running bcp for data import and export, and more.

However, there are significant security risks associated with using it. Therefore, this procedure is disabled by default, and it is not recommended to enable it permanently for security reasons. Users with execute permissions for this procedure can perform any operation on the server. If you intend to use cmdshell, it’s essential to have a strict security policy in place.

How to Enable cmdshell?

Procedure:

  1. Enable the change of advanced server options (show advanced options).
  2. Reconfigure step 1.
  3. Enable the xp_cmdshell feature.
  4. Reconfigure step 3.

Script:

— 1)
EXEC sp_configure ‘show advanced options’, 1
GO
— 2)
RECONFIGURE
GO
— 3)
EXEC sp_configure ‘xp_cmdshell’, 1
GO
— 4)
RECONFIGURE
GO

Rate this post
Category: SQL Administration Useful SQL Scripts

About Ing. Jan Zedníček - Data Engineer & Controlling

My name is Jan Zednicek, and I have been working as a freelance Data Engineer for roughly 10 years. During this time, I have been publishing case studies and technical guides on this website, targeting professionals, students, and enthusiasts interested in Data Engineering particularly on Microsoft technologies as well as corporate finance and reporting solutions. 🔥 If you found this article helpful, please share it or mention me on your website or Community forum

Leave a Reply

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