Copy from a folder to an other

  • Jeff Moden (7/21/2011)


    ALZDBA (7/19/2011)


    Welsh Corgi (7/18/2011)


    There was a post on SSC of an example of the file copy using Powershell about a week ago.

    # copy all jpg files from c:\temp to c:\temp\jpgs

    Copy-Item -Path c:\temp\*.jpg c:\temp\jpgs

    --> lines starting with # are comment lines

    BWAA-HAAA!!!! What's wrong with DOS??? 😛

    COPY c:\temp\*.jpg c:\temp\jpgs

    For once I tried something hip, you didn't see I did wear my cap inside out and transverse 😉

    You know I'm on my powershell learning curve, so that's what came out of my sleeves :hehe:

    Of course there is nothing wrong with yea good old DOS ..... in a sqlagent job please.

    Not in the in-transaction-code !

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • ALZDBA (7/22/2011)[hrOf course there is nothing wrong with yea good old DOS ..... in a sqlagent job please.

    Not in the in-transaction-code !

    I have to disagree there. xp_CmdShell can be used with absolutel safety. It's just that most people won't take the time to learn how even though it's easy. They also won't take the time to learn how to make their applications run without the application login having only PUBLIC privs yet still be able to get the job done. I'm actually doing the research for an article on the methods to do so.

    I know what you're going to say but it's only because of the visceral fear that's been implanted in us all about using xp_CmdShell. Folks should worry more about simply securing their apps instead of xp_CmdShell. Consider this... if someone where to actually delete the DLL for xp_CmdShell yet still allow certain privs by the app (particularly "SA"), I can still get to DOS through OPENROWSET as an attacker and it's an incredibly simple hack.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • ALZDBA (7/22/2011)


    You know I'm on my powershell learning curve, so that's what came out of my sleeves :hehe:

    Granted, the OP could get the job done with CmdShell using COPY instead of the PowerShell command you posted, but I was expecting the OP to ask for some additional criteria along with a basic file copy, like age of file, or something else that could be handled in a one-line PowerShell command that made use of the pipeline.

    I think it's freaking awesome that this is what came out of your sleeve 😎 PowerShell is a complete replacement for CmdShell. While I just started taking it seriously myself I can already say that it supersedes it in countless ways.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Jeff Moden (7/22/2011)


    ALZDBA (7/22/2011)[hrOf course there is nothing wrong with yea good old DOS ..... in a sqlagent job please.

    Not in the in-transaction-code !

    I have to disagree there. xp_CmdShell can be used with absolutel safety. It's just that most people won't take the time to learn how even though it's easy. They also won't take the time to learn how to make their applications run without the application login having only PUBLIC privs yet still be able to get the job done. I'm actually doing the research for an article on the methods to do so.

    I know what you're going to say but it's only because of the visceral fear that's been implanted in us all about using xp_CmdShell. Folks should worry more about simply securing their apps instead of xp_CmdShell. Consider this... if someone where to actually delete the DLL for xp_CmdShell yet still allow certain privs by the app (particularly "SA"), I can still get to DOS through OPENROWSET as an attacker and it's an incredibly simple hack.

    I'm sure one can use xp_cmdshell in a safe way.

    Easiest way is to shut if off to have people reflect at least once more about what they are actually trying to do and the way they are trying to implement.

    IMO it's not because one can do a certain thing using our great engine, one should do it using the engine in every case.

    I fear getting tangled in a web of dependencies no one can overlook. (in either way)

    Hence making control on the system a hell of a job.

    (How about file system locks on objects, ...)

    As in many cases, trying to close doors is a harder job as opening some for certain circumstances.

    And, yes, I must admit it (xp_cmdshell) is an area with a reputation which causes more fear than love for those having to support the engine.

    As always, Jeff, I'm looking forward to your articles.

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • Jeff Moden (7/22/2011)


    ALZDBA (7/22/2011)[hrOf course there is nothing wrong with yea good old DOS ..... in a sqlagent job please.

    Not in the in-transaction-code !

    I have to disagree there. xp_CmdShell can be used with absolutel safety. It's just that most people won't take the time to learn how even though it's easy. They also won't take the time to learn how to make their applications run without the application login having only PUBLIC privs yet still be able to get the job done. I'm actually doing the research for an article on the methods to do so.

    I know what you're going to say but it's only because of the visceral fear that's been implanted in us all about using xp_CmdShell. Folks should worry more about simply securing their apps instead of xp_CmdShell. Consider this... if someone where to actually delete the DLL for xp_CmdShell yet still allow certain privs by the app (particularly "SA"), I can still get to DOS through OPENROWSET as an attacker and it's an incredibly simple hack.

    Granted xp_CmdShell can be rolled out securely. That said, surely you're not going so far as to condone the use of xp_CmdShell within a trigger to copy files...or are you :ermm:

    And throwing in a "visceral fear" reference...you brightened my morning Jeff 😉

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • opc.three (7/22/2011)


    ALZDBA (7/22/2011)


    You know I'm on my powershell learning curve, so that's what came out of my sleeves :hehe:

    Granted, the OP could get the job done with CmdShell using COPY instead of the PowerShell command you posted, but I was expecting the OP to ask for some additional criteria along with a basic file copy, like age of file, or something else that could be handled in a one-line PowerShell command that made use of the pipeline.

    I think it's freaking awesome that this is what came out of your sleeve 😎 PowerShell is a complete replacement for CmdShell. While I just started taking it seriously myself I can already say that it supersedes it in countless ways.

    Yep .... even more dangerous than yea good old DOS :hehe:

    And FWIW same arguments go as for DOS to begin with.

    They might have called it OO-DOS, but would have gotten stuck with the outdated reputation. :rolleyes:

    It is freaking awesome.:-D

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • opc.three (7/22/2011)


    ... surely you're not going so far as to condone the use of xp_CmdShell within a trigger to copy files...or are you :ermm:

    Oh, hell NO! 😀 I frequently "push the envelope" but I don't intentionally look for paper cuts. 😀

    And throwing in a "visceral fear" reference...you brightened my morning Jeff 😉

    I [font="Arial Black"]love [/font]that word... it very quickly and accurately describes "the willies" people get about certain coding techniques. Thanks for introducing me to it.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 7 posts - 16 through 21 (of 21 total)

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