xp_cmdshell
Allow T-SQL to run operating system commands through xp_cmdshell.
- Default
0 (disabled)- Range
- 0 or 1
- Restart needed
- No
- Default checked on
- SQL Server 2025
What it does
Commands run as the SQL Server service account (or a proxy for non-sysadmins), with that account's file system and network access. SQL Server on Linux does not support it: sp_configure rejects the change with Msg 15392.
Default value
0 (disabled). 0 (SQL Server 2025).
Check the current value
SELECT name, value, value_in_use, minimum, maximum, is_dynamic, is_advanced FROM sys.configurations WHERE name = 'xp_cmdshell'; -- EXEC sp_configure 'xp_cmdshell'; also works, but only while show advanced options is 1; -- otherwise it fails with Msg 15123 because this is an advanced option.
Change it
EXEC sp_configure 'show advanced options', 1; RECONFIGURE; EXEC sp_configure 'xp_cmdshell', 0; RECONFIGURE;
No restart: it takes effect when RECONFIGURE runs (sys.configurations.is_dynamic = 1). It is an advanced option, so show advanced options must be on to change it.
When to change it
Keep it off. Use SQL Agent jobs, PowerShell or SSIS for OS tasks.
What can go wrong
Anyone with sysadmin, or an injection running as sysadmin, gets a shell on the host.
Questions about xp_cmdshell
What is the default value of xp_cmdshell in SQL Server?
0 (disabled). 0 (SQL Server 2025).
Does changing xp_cmdshell require a restart?
No. No restart: it takes effect when RECONFIGURE runs (sys.configurations.is_dynamic = 1). It is an advanced option, so show advanced options must be on to change it.
When should I change xp_cmdshell?
Keep it off. Use SQL Agent jobs, PowerShell or SSIS for OS tasks.
Back to all SQL Server settings, or check the SQL Server manual for every option.
Check xp_cmdshell on your own server
SQLly runs the query above against SQL Server and the other engines in this reference, from one desktop app on macOS, Windows and Linux.