Hi,
I have the following problem ,
on some servers xp_cmdshell returns the date in this format
output
Volume in drive D is New Volume
Volume Serial Number is A834-F9EE
NULL
Directory of d:\sqlinstalls\cu6
NULL
03/23/2011 01:51 PM .
03/23/2011 01:51 PM ..
02/04/2011 01:56 AM 8,119,808 sqlncli.msi
02/04/2011 02:38 AM 292,314,464 SQLServer2008R2-KB2489376-x64.exe
2 File(s) 300,434,272 bytes
2 Dir(s) 6,529,056,768 bytes free
NULL
and on others like this
Volume in drive C is OS
Volume Serial Number is 46FC-9B0C
NULL
Directory of c:\
NULL
20/04/2011 16:23 485,098 cybdefauth_i.log
25/04/2011 02:35 21,259 CybDefInstallInfo.log
20/04/2011 16:22 121 CybDefWebInstaller.log
24/08/2010 16:43 d7f152059018fbb2d699e6832fab2157
06/01/2010 12:28 dell
21/06/2011 19:54 Windows
4 File(s) 1,411,182 bytes
17 Dir(s) 77,513,871,360 bytes free
NULL
the problem is with the AM/PM,
I assume it is a locale setting,
Does anyone know what I can check to see the sql server regional setting ?
is it the collation ?
this is messing up a proc I am working on
thanks
↧
xp_cmdshell format returned
↧
How to use xp_cmdshell for NET SEND
Hi,
Can anybody tell me how to use xp_cmdshell for NET SEND , I tried but im getting error msg
The option /ENVENTURE.LOCAL:SQL_USERS is unknown.
NULL
The syntax of this command is:
NULL
NULL
NET SEND
{name | * | /DOMAIN[:name] | /USERS} message
NULL
NULL
More help is available by typing NET HELPMSG 3506.
NULL
NULL
↧
↧
Rename scripted db objects
How can I rename all scripted object files in a folder, to replace 'dbo.' with the object type (Table, view..etc) and remove the appended object type (.Table, .view ..etc) from the file name
As an example: I have 'C:\Tables\dbo.User.Table.SQL'
I want to change that to 'C:\Tables\Table User.SQL'
I tried using xp_cmdshell with rename, but get an 'Access is denied' message.
My Id has sysadmin access on the server and full access to the file.
TIA
↧
How can I export one column as a separate text file for each row?
Let's say I have a table with this info in SQL Server 2008 (2 columns):
DocNumber, Text
0000001, this is the text for doc 1
0000002, this is the text for doc 2
What I need to do, is create text files for each row named by the DocNumber column.
So something like select [Text] from table and then send that to [DocNumber].txt, then loop through the rows. I'm guessing I'll need to use xp_cmdshell.
I need to end up with 000001.txt and 000002.txt.
Any suggestions or resources that might have something similar that I can play around with? It just needs to be a SQL script.
thanks,
Mike
↧
unable to run powershell script from xp_cmdshell
Hi I am very new to powershell but when I run the below command in power shell it executes successfully and gives the required output but when I run the same command in xp_cmdshell it is not giving any output.
declare @sql varchar(2000)
set @sql= 'powershell.exe -c "$strComputer = Get-Content C:\Users\admin\Desktop\servername.txt
foreach ( $computer in $strComputer) {
Get-WmiObject -Class win32_service -computername $computer | where {$_.name -like ''MSSQLServer'' -OR $_.name -like ''MSSQL$*'' -OR $_.name -like ''SQLAgent$*'' -OR $_.name -like ''SQLSERVERAGENT'' } | select-object Name,state,systemname,startmode,startname}"'
print @sql
EXEC xp_cmdshell @sql
Can somebody help me on this ? I am stuck with this part.
Thanks
On advance
↧
↧
Running xp_cmdshell as Administrator
Does anyone know if it is possible to invoke xp_cmdshell as Administrator? I am working on trying to start the SQLSERVERAGENT service from TSQL but it fails with 'access denied' - from TSQL and from cmd.
The only way I can get it to succeed is to run cmd as Administrator and then `SC START SQLSERVERAGENT` works.
I dont want to alter UAC to get around this problem.
↧
XP_CMDSHELL Proxy Failover Cluster
I have 2 instances setup in an active active failover cluster. I am having some trouble setting up a proxy account for xp_cmdshell. When I set up xp_cmdshell proxy for a user lets call it "testuser" on instance 1 all works fine. The issue I am seeing is when I failover instance 1 to instance 2 then the "testuser" can no longer execute xp_cmdshell commands.
Is there something specific I need to do to have this work in a failover situation? The credential identity Domain is pointing to the computer name of instance 1.
I get this error message:
Msg 15153, Level 16, State 1, Procedure xp_cmdshell, Line 1
The xp_cmdshell proxy account information cannot be retrieved or is invalid. Verify that the '##xp_cmdshell_proxy_account##' credential exists and contains valid information.
↧
Xp_cmdshell throw error with hyphen in server name
Hi, Please help me to resolve the issue. I am using BCP OUT to export data into text file. My server name has - (hyphen) like SERVER-NAME. BCP out is not recognising - (hyphen) and thows error. I tried double quotes like "SERVER-NAME" also [SERVER-NAME], Still i am getting error.
Please suggest me how to deal with it.
↧
Move files from one folder to another
I am trying to move file from D:\try\t1.txt to folder D:\trycopy\
EXEC master..xp_cmdshell 'MOVE /Y D:\try\t1.txt /B D:\trycopy\'
But its not moved.
Error "The system cannot find the file specified."
t1.txt file is there on the respective file.
↧
↧
How To Configure xp_cmdshell To Access Remote Server?
Hi there,
I'm trying to get xp_cmdshell to provide a directory listing of all files and folder on a remote server. When I run the command in a command prompt window it executes fine:
dir \\files\1234
However whenever I try to execute the same command from query analyzer using xp_cmdshell it errors:
"Logon failure: unknown user name or bad password."
The command I am running is:
exec master.dbo.xp_cmdshell 'dir \\files\1234'
How to configure the xp_cmdshell to execute successfully on the remote server?
TIA.
↧
what is the replacement of xp_cmdshell in sql server 2014 or 2008
Hi,
I needs to read the zip files and write create the same zip file using sql server (with out xp_cmdsehll),Please help me
↧
sometimes xp_cmdshell showing null
Hi
sometimes xp_cmdshell showing null and sometimes its working fine... i dont know what wrong with this
Any suggestions
↧
exec master.dbo.xp_cmdshell variable error
PLease help. What is wrong with my TSQL? It states The filename, directory name, or volume label syntax is incorrect.
DECLARE @databasename varchar (200)
DECLARE @cmd varchar (300)
DECLARE @pathfile varchar (150)
DECLARE @destinationfile varchar (150)
SET @destinationfile='\\SHDVNFDBV1\shared-backup'''
SET @PATHFILE='''copy"G:\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\Pedialink\'
SET @databasename='Pedialink_Full_'
set @cmd=@pathfile+@databasename + (SELECT CONVERT(char(10), GetDate()-1,126))+'.ls"'+SPACE(1) + @destinationfile
select @cmd
exec master.dbo.xp_cmdshell @cmd
OUTPUT
The filename, directory name, or volume label syntax is incorrect.
↧
↧
sql agent job/xp_cmdshell batch file: How to capture output and/or error?
I am using a sql agent job that uses xp_cmdshell to execute a batch file.
The batch file runs several sql scripts using sqlcmd. It appears to be working.
However, I am unable to capture any error. If I force one of the sql statements to fail,
the sql job still finishes successfully. It doesn't appear to see the error the
batch file would typically show had I executed it via a command prompt.
Is there a way to capture the dos and sql print statements that you would see if you
were to run it via a command prompt? And to capture an error?
My T-sql looks like this:
SELECT @cmd= ProcessPath+ProcessFilename
FROM AgentJobProcessPath
EXECUTE master..xp_cmdshell @cmd
I have tried several other things to get the output from the batch file execution to display
in the job history or elsewhere. Below are the things I've already tried.
I have tried:
CREATE TABLE #output (OutputField nvarchar(4000))
Insert into #output (OutputField) EXECUTE master..xp_cmdshell @cmd
SELECT OutputField FROM #Output WHERE OutputField is not null
When I try this, and view my job history, there is still no output;
also tried:
DECLARE @result int;
EXEC @result = xp_cmdshell @cmd;
IF (@result = 0)
PRINT 'Success'
ELSE
PRINT 'Failure';
In this, @result is ALWAYS 1 even when the sql does NOT produce an error.
also tried:
SELECT @cmd = @PathFile + ' > \\networkpath\folder\output.txt'
This created the output.txt file, however, it was always empty;
also tried:
In the SQL Agent job step itself, I went to the advanced tab, and checked the 'Include step output in history'. But there is still no output from the batch file there to view.
When I viewed the job history for the step, it was still mostly empty, no output from the batch file.
Thank you in advance for any assistance, it is much appreciated!!
Stacy
↧
Executing powershell from xp_cmdshell
I have a powershell file that looks to a directory and locks the fields on each of the Word documents that are contained in that directory. I am executing this powershell file from a SQL stored procedure using xp_cmdshell.
I have implemented this solution at several organizations without a problem.
I am currently implementing this at another organization, but am having problems. At this new organization, if I execute the powershell file manually from within a Powershell window, the script runs successfully and locks the fields on each of the documents. However, when the same PS file is attempted to be run from the SQL stored procedure via xp_cmdshell, I am getting the following error message:
![alt text][1]
I believe that this organization is on the same versions of SQL, Powershell, and Windows as the organization where this does work successfully. I'm suspecting that this might be some sort of permissions or SQL configuration issue but am at a loss at this point. Any ideas?
[1]: /storage/temp/3314-capture.jpg
↧
remote deleting files, where names are in a table, across servers
I have a table that lists file-names that have been created on an App server.
Goal: I want to keep the list of files in the SQL server table and the list of files on disk on the App server in sync.
The table has the file name in it (nothing else). The App server name can be hard coded. The directory where the files are located can be hard coded. The list of file-names changes each day and needs to be purged nightly off of the SQL server table and the App server directory.
I can write a set of SQL to select the files to delete no problem. I have not been able to find a way to remotely delete on the app server.
I have explored xp_cmdshell (if I were deleting on the SQL server I would be done), mstsc, rdp looking for remote execution of a DEL command. I have not been able to figure a way to invoke deleting those files from the SQL server.
Any help is appreciated. Thank you for your help and time.
↧
I am trying to execute a vbscript program from a sql after insert trigger by passing parameters to my vbscript file using xp_cmdshell but I am getting run time error
My SQL Trigger code is
IF OBJECT_ID('TRG_InsertEmp1') IS NOT NULL
DROP TRIGGER TRG_InsertEmp1
GO
CREATE TRIGGER TRG_InsertSyncEmp1
ON dbo.Emp_details
AFTER INSERT AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for trigger here
DECLARE @cmd varchar(20),@empid as Int, @empname varchar(10), @empsal int
Set @empid= (select EmpID from inserted)
Set @empname=(select EmpName from inserted)
Set @empsal=(select EmpSal from inserted)
set @cmd='Cscript.exe C:myTestScript.vbs"/parameter1:@empname/parameter2:@empname/parameter3@empsal"'
exec xp_cmdShell @cmd
END
GO
My vbscript program which tries to print the parameters passed from SQL logic is
'VBScript program myTestScript.vb
if WScript.Arguments.Count = 0 then
WScript.Echo "Missing parameters"
end if
Wscript.Echo Wscript.Arguments(0)
WScript.Echo Wscript.Arguments(1)
WScript.Echo Wscipt.arguments(2)
But I am getting the following error on SQL Server Management Studio
Msg 8152, Level 16, State 14, Line 1
String or binary data would be truncated.
The statement has been terminated.
I Will be grateful for any help/example code on how to resolve this or accomplish my task of passing above parameters to a vbscript file
↧
↧
Altering credential ##xm_cmdshell_proxy_account## for xp_cmdshell
Current situation We have - 2 SQL Server 2014 instances (including the latest service packs)
- each on a different Window 2012R2 machines. - with each a different windows accounts for the ##xm_cmdshell_proxy_account##.
On both systems the xp_cmdshell works completely fine.
Important not: One account is: - the AD Administrator - and the other one is a normal Active Directory account with administrator privileges (lets call this one NormalAdmin).
Change Because both are windows administrators we like to change them to non-administrator accounts.
There has been created an new account for this goal. - It has rights to run applications on the places where it needs to - It has rights to access and modify files in the filesystem - It has access to the databases it needs to - The account is member of the master database - And is granted rights to run the xp_cmdshell command
But: - It still cannot perform dir commands - Or run bat-files
Questions Because all the steps mentioned in manuals have been taken, I am not able to make the question more clearer than: - So, what to do next?
↧
Save PowerShell variables Within xp_cmdshell
Does anyone know if it is possible to save POWERSHELL variables when using xp_cmdshell when calling powershell code? The code below returns NULL when run from within SSMS but it should return HELLO as that is the variable I am storing in $test
declare @sql as varchar(255)
set @sql = 'powershell.exe -c "$test = ''hello''
$test"'
EXEC xp_cmdshell @sql
↧
Using xp_cmdShell: I get 'access denied' copying a file from a server on a domain to the SQL server
I have given my user (acg\\edc) full access to both folders. I have even got desperate enough to give 'everyone' access to the folder on the domain server to no avail.
Please find the TransactSQL I have used following...
-- Configuring to use xp_cmdshell
-- ==============================
use master
EXEC sp_configure 'show advanced options', 1
go
RECONFIGURE
go
EXEC sp_configure 'xp_cmdshell', 1
go
Reconfigure
GO
-- Configure proxy account
-- =======================
--The following did not work
exec sp_xp_cmdshell_proxy_account 'acg\edc', 'Doc@2007'
go
--The following worked
create credential ##xp_cmdshell_proxy_account## with identity = 'acg\edc', secret = 'Doc@2007'
--Just in case I allowed the same user to use xp_cmdshell. (Possibly not necessary)
GRANT exec ON xp_cmdshell TO [acg\edc]
-- Finally the code I am using to test the problem
-- ===============================================
declare @cmd nvarchar(500)
declare @Source nvarchar(255) = N'\\assessing-fs\Document Store System\Document Store\17\06\0244\1387684.PDF'
declare @Destination nvarchar(255) = N'C:\Export to CMC Web Page\Assessing\3PQ22KYP.PDF'
set @cmd = 'copy "' + @Source + '", "' + @Destination + '"'
exec master.dbo.xp_cmdshell 'whoami.exe'
EXECUTE AS LOGIN = 'acg\edc'
exec master.dbo.xp_cmdshell 'whoami.exe'
exec master.dbo.xp_cmdshell @cmd
REVERT
exec master.dbo.xp_cmdshell 'whoami.exe'
--Finish
my output results for the last section ( the whoami.exe and the copy) are...
nt service\mssqlserver
nt service\mssqlserver
access is denied.
nt service\mssqlserver
I have spent a week on this now and I am at my wits end. I am really hoping their is a way through this.
↧