How to get count of files copied using Copy-item

This topic contains 2 replies, has 2 voices, and was last updated by  Dinesh Kumar 4 weeks, 1 day ago.

  • Author
    Posts
  • #102805

    Dinesh Kumar
    Participant

    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

    Don Jones
    Keymaster

    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

      Dinesh Kumar
      Participant

      Thanks for the response. Its working as expected.

You must be logged in to reply to this topic.