Unable to run Dir using xp_cmdshell

  • Hello,

    When I run the below command from PRod server to connect to a Non Prod server to see if that can fetch the details,

    I get error -

    xp_cmdshell 'Dir \\full server name\D$\MSSQL\BACKUP\folder\'

    Output:

    The user name or password is incorrect.

    NULL

    Is there anyway to force connect keeping in mind a proper security context.

    How does sp_xp_cmdshell_proxy_account help? I tried to get some more help but did not get much. If you could suggest.

    EXECUTE sp_xp_cmdshell_proxy_account 'domain\useracc','pass'

    My ultimate object is to copy bkp files from PRod to Non Prod but both servers are in different domain.

    Thanks.

  • If the path has spaces, use double quotes around it.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Basically trying to copy the bkp file from one server to another but both the servers are in two diff domains.

    There is no space and I'm using double quotes.

    EXECUTE xp_cmdshell 'copy "\\Prod_server\D$\MSSQL\BACKUP\bkp1.bkp" "\\dest_server\D$\MSSQL\BACKUP\"'

    GO

    Thanks.

  • I'll guess that you have a proxy account set to use xp_cmdshell. I'm also guessing that you're not using a sysadmin account to run xp_cmdshell. Then, I'll guess that the account set with sp_xp_cmdshell_proxy_account wasn't set correctly. If I'm correct, you'll have to make sure that you have the correct account and password for the proxy.

    If I'm wrong, you should check permissions for the account used by xp_cmdshell.

    This might help you: http://www.sqlservergeeks.com/sql-server-xp_cmdshell-proxy-account-information-cannot-be-retrieved-or-is-invalid-verify-that-the-xp_cmdshell_proxy_account-credential-exists-and-contains-valid-information/

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • I already have a Proxy account set. I am calling the xp_cmdshell using the SQL SSMS so I hope it should use sysadmin rights. No?

    In order to use the proxy account while calling xp_cmdshell, how to modify the code?

    Thanks.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply