0

I am busy with creating a PowerShell script where a folder needs to be copied to another folder as a part of the script. For this I would like to use the standard Windows copy interface and leverage from the prompts and selections like “There is already a file with the same name in this location.”, “Do you want to merge this folder”, “Do this for all”, etc. instead of programming this all myself.

I investigated a view directions:

  • Using the IFileOperation::CopyItem method as e.g. HowTo: Display progress dialog using IFileOperation but I could find any hint of how to embed this in PowerShell
  • Using Verbs() Copy/Paste but although the example Invoke-FileSystemVerb -Path "C:\TestDir -Verb Cut; Invoke-FileSystemVerb -Path "\\server\share" -Verb Paste” suggests otherwise, I can paste files that are manually copied/cut but could not copy/cut files with using the CmdLet or simply using the Verb.DoIt() method (I suspect this for a security reason).
  • Simulate a drag-drop?

But could not find any working solution. Any suggestion how to do this from PowerShell?

Community
  • 1
  • 1
iRon
  • 20,463
  • 10
  • 53
  • 79

1 Answers1

4

I use this to extract from ZIP files which seems to come up with all the prompts and progress bar:

$shell = New-Object -Com Shell.Application
$folder = $shell.NameSpace(“$path\Folder”)
$shell.NameSpace($otherpath).CopyHere($folder)
Deadly-Bagel
  • 1,612
  • 1
  • 9
  • 21
  • Thanks, I was lonking for such a solution for hours and this seems indeed to do the trick. – iRon Nov 17 '15 at 15:19
  • Instead of the `ForEach` loop it is better to copy all items at once: `.CopyHere($zip.items())` this will also show the "_Do this for all_" for the root items. – iRon Nov 17 '15 at 15:30
  • I modified it to copy the entire folder rather than its contents, which is far neater IMO (unless you want to only copy the contents) – Deadly-Bagel Nov 17 '15 at 15:35
  • The `CopyHere()` hint help me a lot but I am using a little different implementation as I want to copy all the items in the $Folder and not the top folder itself: `$Shell.Namespace($LocalDestination).CopyHere($Shell.NameSpace($RemoteSource).Items())` – iRon Jan 06 '16 at 08:00