How to copy certain files (w/o folder hierarchy), but do not overwrite existing files?

后端 未结 5 2062
孤街浪徒
孤街浪徒 2020-12-08 09:03

I need to copy all *.doc files (but not folders whose names match *.doc) from a network folder \\\\server\\source (including files in

5条回答
  •  被撕碎了的回忆
    2020-12-08 09:31

    Why use foreach when you already have a pipeline? Calculated properties for the win!

    Get-ChildItem -Recurse -Path:\\Server\Path -filter:'*.doc' | 
        Where { -not $_.PSIsContainer } |
        Group Name |
        Select @{Name='Path'; Expression={$_.Group[0].FullName}},@{Name='Destination'; Expression={'C:\Destination\{0}' -f $_.Name}} |
        Copy-Item
    

提交回复
热议问题