Enable and disable xp_cmdshell using sp_configure

By default, xp_cmdshell is disabled in SQL Server for security reasons, and can be enabled by running the sp_configure system stored procedure:

EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE
GO

To display all configuration options run:

EXEC sp_configure

To disable xp_cmdshell run this code:

EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
EXEC sp_configure 'xp_cmdshell', 0
GO
RECONFIGURE
GO