How to get count of files copied using Copy-item

Welcome Forums General PowerShell Q&A How to get count of files copied using Copy-item

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
4 months ago.

  • Author
    Posts
  • #102805

    Participant
    Points: 0
    Rank: Member

    Hi,

    I am using Copy-Item command to copy the multiple files from one location to another. In that, I want to get the count of files that are copied to destination.

    If the above one is not possible, can we get 'True' if at least one file is copied and 'False' if none of the files are copied.
    I tried this but could not able to get exact one.

    Thanks,
    Dinesh

  • #102808

    Keymaster
    Points: 7
    Rank: Member

    Sure. Many commands, including Copy-Item, have a -PassThru parameter, which causes them to output the object they just acted against.

    Copy-Item a b -PassThru | Measure-Object

    By outputting the acted-upon objects, you can pipe them to Measure-Object to count them.

    • #102815

      Participant
      Points: 0
      Rank: Member

      Thanks for the response. Its working as expected.

The topic ‘How to get count of files copied using Copy-item’ is closed to new replies.