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.

Filter by
Sorted by
Tagged with
0
votes
1answer
93 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
240 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
292 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 ...
1
vote
2answers
1k 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
39 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
56 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
36 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
1k 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
1answer
2k views

How to save a varchar(MAX) to a file?

For my own records I have a table in one of my servers where I like to save my activities and scripts the table definition is: IF OBJECT_ID('[dbo].[activity]') IS NOT NULL DROP TABLE [dbo].[...
1
vote
0answers
79 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
225 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
137 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
400 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
454 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
598 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
260 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
443 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
3k 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
111 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
1k 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
4k 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
6k 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 ...
5
votes
3answers
47k 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
6k 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
5k 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
1k 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.
7
votes
2answers
691 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
7k 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 ...