Questions tagged [xp-cmdshell]

an extended stored procedure provided by SQL Server, which launches a Windows command shell to run a specified command. Not for general questions about cmd.exe or batch scripting; not related to Windows XP.

The xp_cmdshell extended stored procedure runs the command string given and returns any output as rows of text. The documentation (for SQL Server 2012) can be found here.

For security reasons, xp_cmdshell is disabled by default in recent versions of SQL Server.

264 questions
4
votes
2 answers

Enable xp_cmdshell does not work

I try to enable xp_cmdshell in SQL Server. So I ran: EXEC master.dbo.sp_configure 'show advanced options', 1 RECONFIGURE EXEC master.dbo.sp_configure 'xp_cmdshell', 1 RECONFIGURE The returned message says: Configuration option 'show advanced…
Shawn
  • 5,130
  • 13
  • 66
  • 109
4
votes
1 answer

bcp - dump via xp_cmdshell vs. sp_oaMethod Security

I'm using Microsoft SQL Server 2008 R2 and I try to dump a table via bcp (with a scheduled Job). First of all I implemented it with xp_cmdshell, but I've heard, that this should be avoided due to security reasons. So my question: What's about…
3
votes
4 answers

Copy a file from one dir to another by date

I have this SQL Job (in SQL Server 2005) that creates a backup every six(6) hours, the backup's filename is based on the timestamp so that it will create a unique filename(dbname_yyyymmddhhmmss.bak), Now my question is, How would I know using…
KG Sosa
  • 21,565
  • 6
  • 26
  • 27
3
votes
1 answer

xp_cmdshell on SQL Server Linux Public Preview

I am using the Public Preview of SQL Server 2016 on Linux. I am trying to run xp_cmdshell and get the following error. I suspect it has to do with permissions but have no idea how to fix this. I have spent many hours searching for some answers but…
smucha
  • 55
  • 2
  • 7
3
votes
1 answer

psexec does not work properly when called from xp_cmdshell

I want to run a jarfile from an SQL Server to a different machine remotely. To do this, I found out I can use PSEXEC to send commands remotely to the target machine and use xp_cmdshell so I can call psexec command form a stored procedure. I already…
Krish
  • 319
  • 4
  • 19
3
votes
1 answer

Passing variable into xp_cmdshell

I have a stored procedure in SQL Server that checks for today's backup files (files that has a date in its filename). After checks, it will move on to robocopy these files to another folder. The challenge: In this folder, there could be files from…
Haans
  • 73
  • 1
  • 1
  • 7
3
votes
2 answers

sql sp_xp_cmdshell_proxy_account error

when I run the following command in sql on ly local PC: EXEC sp_xp_cmdshell_proxy_account 'pc-name\my_username', 'password' I'm getting the error: An error occurred during the execution of sp_xp_cmdshell_proxy_account. Possible reasons: the…
Buda Gavril
  • 21,409
  • 40
  • 127
  • 196
3
votes
2 answers

Why can I run .bat from SQL Server but not .exe?

I can run my.exe from the command line. I can run it from a .bat. But, when I try to run them in SQL Server the .exe appears to never run. exec master..xp_cmdshell '\\fs01\filefolder\runpgm.bat' This does run the .bat but the .exe it runs is never…
maxweber
  • 576
  • 1
  • 5
  • 12
3
votes
5 answers

I'm missing something

declare @servername varchar(2000) set @EmriServerit=(select @@servername) declare @dbname varchar(2000) set @dbname ='Test1' declare @Dir varchar(2000) set @Dir='F:\dataclient.sql' exec master.dbo.xp_cmdshell 'osql -E -S ' + @servername+ ' -d ' + …
Redi
  • 163
  • 1
  • 10
3
votes
2 answers

How to combine stored procedure and select query result?

I am trying to combine the results of xp_cmdshell with a select query. I have tried union & read about creating a temp table, but as my result will be having only 1 column. To be more precise i need a smaller query to combine the results of…
AJINKYA
  • 741
  • 2
  • 9
  • 20
2
votes
0 answers

SQL xp_cmdshell not recognising R library package

I cannot seem to get SQL xp_cmdshell to run an R script that includes loading a library. Am using Windows 10, MSSQL v15, R4.1 What I am trying to do is run an R script that has several libraries that load. It is running fine in RStudio and via…
LukeB
  • 21
  • 4
2
votes
2 answers

Efficient Script to get all Extended File Properties

I'm pretty new working with Powershell and i have some working code but I'm not sure how to get it into an efficient routine to return all of the extended file properties of some video files i have. I have: # The basic setup for the next steps $path…
jimerb
  • 67
  • 9
2
votes
0 answers

SQL Server's xp_cmdshell is slow after updates

After updating Windows and SQL Server, xp_cmdshell is running slowly. We are running Windows Server 2016 with SQL Server 2016 SP1. We've fully updated SQL Server to SP2 CU8 with no change in behavior. The performance of our Windows Server seems…
Zaulism
  • 21
  • 1
2
votes
1 answer

Error occurs when try to "EXECUTE Master.dbo.xp_CmdShell" commands through web request from database trigger to create text file locally

Requirement: I want to create text file from SQL-Server DB trigger using cmdshell commands(mentioned in title). Scenarios: S1: When I am trying to execute cmdshell command(mentioned in title) from trigger to create text file and write some content…
2
votes
1 answer

exec xp_cmdshell bcp syntax

I can't seem to find the right syntax to export data with column names using exec xp_cmdshell bcp in sql server management studio.I've tried the below variations EXEC xp_cmdshell bcp "select "a_id","b_id","c_id" union select a_id,b_id,c_id from …
nobody
  • 10,892
  • 8
  • 45
  • 63
1
2
3
17 18