Questions tagged [xp-cmdshell]
xp_cmdshell is a Microsoft SQL Server extended stored procedure one can use to spawn a windows process to execute a command line. Questions in this tag should be about using this procedure.
37
questions
0
votes
1answer
207 views
How to use BCP Utility queryout in a network path with crededential (login required) for SQL Server
I'm having a hard time figuring out on how can I export my selected table in a network path that requires login credentials.
'bcp "select ''StudentName'' UNION ALL SELECT StudentName AS ...
1
vote
0answers
274 views
Is it possible to use OAUTH2 in MS SQL Server
I am using msdb.sp_senddbmail procedure to send emails from MS SQL Server but now I need to move to OAUTH2.
I tried to implement separate application and call it from procedures using xp_cmdshell but ...
0
votes
1answer
282 views
Copy last modified files from network path into SQL server box and rename them using Agent job
I have to copy latest backup from a network path and bring that to my SQL server physical drive for restore, I have to do that using agent job.
This is what i am doing.
Created a SQL server agent ...
1
vote
2answers
3k views
SQL Server works slow after enable XP_CMDShell even disable until restart service
2 days ago I created a function that needs INSERT and UPDATE, and I enabled XP_CMDShell and do it by running a script.
Afterwards, SQL Server works very slow for SELECT commands. Even very simple ...
4
votes
2answers
919 views
xp_cmdshell called from procedure WITH EXECUTE AS OWNER
I am trying to understand details of wrapping xp_cmdshell functionality in user defined stored procs, so that other users can just be given execute permission to the stored procs rather than ...
1
vote
1answer
78 views
Cannot take backup into NAS storage at specific time
I have a job which runs every 30 minute and takes t-log backup of the database suing Ola's script. Every Thursday and Friday at 22:45 I get an error:
11/07/2019 22:45:00,Backup,Unknown,Error: 3041<...
0
votes
1answer
666 views
error 15466 An error during decryption
I have a stored procedure that runs xp_cmdshell with a user with sysadmin right.(it was created by someone else long time ago). For security purposes I need to remove the sysadmin right from this user....
0
votes
0answers
921 views
SQL Server 2016: Run xp_cmdshell as a different sysadmin user aside from the SQL Server service account
I been trying to research this for hours and can't seem to find anything. Basically what I am trying to do is run a xp_cmdshell command as a currently signed in sysadmin user
To give some background, ...
0
votes
2answers
627 views
Copy files twice using xp_cmdshell
When I run this command
exec xp_cmdshell 'copy C:\---\cmdshell1\a23.txt C:\---\cmdshell2';
It copies a23.txt file from cmdshell1 to cmdshell2 folder.
When I run the same command second time it does ...
2
votes
2answers
4k views
how to get the date of a file using xp_cmdshell?
So far I've this code
CREATE TABLE #tmp (strData VARCHAR(1000))
INSERT INTO #tmp EXEC xp_cmdshell 'dir C:\Users\Giba\Desktop\Folder\cmdshell1\*.txt'
SELECT * FROM #tmp --WHERE strData LIKE '09/25/...
1
vote
1answer
58 views
Use T-SQL to return free space on a network share
I'd like to be able to calculate the amount of free space I have for offsite backups so I can prevent any jobs from running should there not be the relevant space and also be able to send alerts when ...
1
vote
0answers
495 views
Viewing directory of a mapped drive
I'm using the following query to view files/folders in a given directory. It works locally, but when trying to view a mapped drive I get...
"The system cannot find the path specified."
I have the ...
1
vote
1answer
129 views
Connection is Using Properly or not in Net Use via SQL Procedure
am doing an operation of creating a file and writing in a SAN SAMBA where it will be done using the cmd_shell via SQL Procedure. It's creating and writing it successfully but while am calling that ...
5
votes
3answers
2k views
Invoke SQLCMD doesn't work when used with xp_cmdshell
I am trying to get disk space report from bunch of servers and insert them into sql table..
below is sample of what i am trying to do,Server names will be populated from a table and passed as a ...
1
vote
0answers
105 views
xp_cmdshell - Enablement Consequences - Clarifications
Recently we have disabled a module which is dependent on xp_cmdshell. Though we are not directly using the xp_cmdshell (instead we are using the proxy), we would now like to disable the xp_cmdshell ...
1
vote
1answer
344 views
xp_cmdshell Date Parameter - Looks for File create Date of last modify date? [closed]
While deleting files using xp_cmdshell, does the date column look for file creation date or last modified date?
0
votes
1answer
177 views
DAC Connection using the SSMS for executing the code
Can anyone help me on below . I am trying to execute the SQLCMD with DAC (-A switch) but unable to do so .
How can I do it both ways below :
Execute in SSMS Query Pane
Execute using PowerShell
...
0
votes
1answer
756 views
SQL Server 2014: Using gMSA for xp_cmdshell Proxy Account?
We are running SQL Server 2014. We want to use a gMSA as the proxy account for xp_cmdshell.
I tried running the following:
EXEC sys.sp_xp_cmdshell_proxy_account 'gmsaNameGoesHere$', ''
However, it ...
0
votes
2answers
667 views
String replacement in SQLCMD
I'm trying to set up a test environment that simulates (very roughly) having three servers. I'm doing this by creating 3 databases on my local instance of SQL which I'll call [A], [B], and [C]. Why I ...
5
votes
2answers
825 views
How can I save the results of DBCC SHRINKFILE into a table?
I have the following script:
-- available space in each of the database files
PRINT @@SERVERNAME
--SQLDWDEV01
USE [BodenStage]
GO
SELECT name
,(CAST(ROUND((size/128.0 - CAST(FILEPROPERTY(name, '...
0
votes
2answers
323 views
xp_cmdshell only sends first character of string
I am trying to use xp_cmdshell to launch a python script with a list as its input but for some reason its only passing the first character of the string to command line. The result I get from the code ...
-1
votes
2answers
596 views
execute un file via xp_cmdshell
my text file cmdftp_put.txt contain the following:
open ftp.xxx.com
loginxx
pwdxx
put C:\Mydatabase.bak /Sources/Mydatabase.bak
quit
I want to execute this file through an xp_cmdshell in order to ...
3
votes
3answers
2k views
Is it safe to set xp_cmdshell value 1?
I need to use xp_cmdshell in one of SQL job.So is it safe to reconfigure xp_cmdshell to 1 or can i set value 1 in the starting of SQL statements and set it back to 0 in the end of SQL Statement ?
4
votes
3answers
4k views
Execute xp_cmdshell as a non-windows user
So I have a bunch of database users who should be able to execute a procedure with a call to xp_cmdshell. They are not windows domain accounts, they are just sql-server logins. I want to do it using a ...
0
votes
1answer
147 views
Change the Hosts files on both SQL nodes to show 127.0.0.1 LocalHost
How to do this ?
Change the Hosts files on both SQL nodes to show 127.0.0.1 LocalHost
5
votes
6answers
2k views
Alternative to xp_cmdshell for emailing a report as a CSV file
I've got an issue that I could do with some ideas as to how to achieve what's needed without using (or enabling) xp_cmdshell if possible.
I know that xp_cmdshell itself poses risks, even with a proxy ...
3
votes
1answer
5k views
“Access is denied.” for xp_cmdshell for network share
On a SQL 2014 SP 1 instance a SQL Agent job I'm using xp_cmdshell to return a list of files from a network share. This has recently stopped working and returns "Access is denied."
The command is ...
4
votes
1answer
3k views
When executing a command via xp_cmdshell what user issues the command to the system?
I'm executing the following command to stop a service on a remote server from within a stored procedure in SQL Server.
----------------
-- Stop Service
----------------
SET @Command = 'sc \\' + @...
2
votes
2answers
9k views
CMDEXEC The process could not be created for step… (reason: Access is denied). The step failed
I have created a job to test executing a CmdExec step. The job step is simply executing a batch file with dir as the command.
The job is executing as the SQL Server service account. This account ...
10
votes
3answers
70k views
“Unable to Open BCP host data-file” using xp_cmdshell from SSMS but command line works
I have a stored procedure that runs on a job every once in a while to BCP some files left by an application I've written.
I noticed the files were piling up and BCP wasn't picking them up so I ...
0
votes
1answer
8k views
EXEC master.dbo.xp_cmdshell 'The user name or password is incorrect'
I am trying to move a file from a network drive to another server and when I execute this statement. I get an output of
The user name or password is incorrect
DECLARE @SourceFile AS VARCHAR(500); ...
1
vote
3answers
6k views
Using Echo statement writes Echo is ON in the text file
Following code is used for write a number in the text file but instead it is writing "Echo is ON" into the text file.
SET @CMD = 'ECHO '+@Ver+'>'+@Vercheck
Print @CMD
EXEC xp_cmdshell @...
1
vote
4answers
2k views
UNION xp_cmdshell
I'm trying and failing to do something a follows
select 1 union xp_cmdshell 'whoami'
Is there anyway to get this work? The simpler the better i.e. one statement.
0
votes
1answer
331 views
SQL Server DeleteFolder Job ran successfully but it doesn't deleted the folder
I have a job to delete past 15 days folder in SQL Server. The job run successfully and delete the folder in local SQL Server.
But it runs successfully and does not delete the folder in another SQL ...
7
votes
2answers
878 views
Why is script with “ xp_cmdshell ” in comment failing with a transport level error?
When executing the following batch that is part of a large script:
...
GO
-----------------------------------------------------------------------------------------------
-- Removed the xp_cmdshell ...
6
votes
2answers
3k views
problem running xp_cmdshell when Application Name set in connection string
I have an app on 10 or so servers that runs a few xp_cmdshell statements against MSSQL 2008. It works fine on all the servers except for one. To make things worse, I can run all the commands in SQL ...
6
votes
2answers
8k views
Can we minimise the risk of using xp_cmdshell?
Using xp_cmdshell can be quite helpful and sometimes possibly the only answer to some scenarios. I've read some posts on the internet that enabling xp_cmdshell might jeopardize the security of the ...