Advice on Agent job step

  • He everyone.

    I have a requirement to move a .xlsx file from a local location to a sharepoint site.

    I looked around I saw advice that suggested mappping Sharepoint site as a mapped drive location, which I have done.

    The line below works fine when exectuted from cmd prompt. It moves the file to Sharepoint location.

    It fails when I try to run it as a SQL agent job when Job type is Operating System (CmdExec)

    XCopy "C:\SQL\PowerShell\Failedjobs.xlsx" J:\ /y

    Would anyone be able to advise me what I have done wrong in the script in order for it to be able to be run as a SQL agent job ?

    Do I need the full Sharepoint URL, have tried many combinations but with no luck.

    Error I get is : Invalid drive specification 0 File(s) copied. Process Exit Code 4. The step failed.

    So I have incorrectly named the location it needs to go to, but do not know what to do to correct it ?

    Thanks for any advice.

  • it may be permissions. Does the agent service have permission to the sharepoint folder? if permissions are correct you could try the actual path instead of mapped drive. something like:

    XCopy "C:\SQL\PowerShell\Failedjobs.xlsx" \\site.domain.com\DavWWWroot\site\Documents\ /y

    SQL server may have issues writing to a webdav folder.

    my question would be, why are you using SQL agent to copy a file that (based on the source folder) looks like it was created with powershell? If you are using powershell to create the file, why not just user powershell to copy the file.

    copy-item C:\SQL\PowerShell\Failedjobs.xlsx -destination \\site.domain.com\DavWWWroot\site\Documents\

    Bob
    -----------------------------------------------------------------------------
    How to post to get the best help[/url]

  • Robert klimes (10/3/2013)


    it may be permissions. Does the agent service have permission to the sharepoint folder? if permissions are correct you could try the actual path instead of mapped drive. something like:

    XCopy "C:\SQL\PowerShell\Failedjobs.xlsx" \\site.domain.com\DavWWWroot\site\Documents\ /y

    SQL server may have issues writing to a webdav folder.

    my question would be, why are you using SQL agent to copy a file that (based on the source folder) looks like it was created with powershell? If you are using powershell to create the file, why not just user powershell to copy the file.

    copy-item C:\SQL\PowerShell\Failedjobs.xlsx -destination \\site.domain.com\DavWWWroot\site\Documents\

    Bob

    Thanks so much will try powershell method tomorrow and let you know.

    Permissions are ok as agent account has permissions to save to that location.

    I prefer the powershell method , but was struggling to get it to work so was trying different approach.

    thanks again

Viewing 3 posts - 1 through 2 (of 2 total)

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