-- xp_cmdshell is an advanced option,
-- so first you need to check if it's turned on:
EXEC sp_configure;
GO
-- If you don't see xp_cmdshell in the list:
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
GO
-- Check the status of xp_cmdshell.
-- If necessary turn xp_cmdshell on:
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;
GO
-- Do stuff
-- If xp_cmdshell is no longer needed:
EXEC sp_configure 'xp_cmdshell', 0;
RECONFIGURE;
GO
-- If advanced options are no longer needed:
EXEC sp_configure 'show advanced options', 0;
RECONFIGURE;
GO