void CopyContainerToContainer(ContainerCmdletProvider provider, string srcPath, string destPath, bool recurse, CopyContainers copyContainers, ProviderRuntime runtime) { // the "usual" case: if we don't use recursion (empty container is copied) or we want to maintain the // original hierarchy if (!recurse || copyContainers.Equals(CopyContainers.CopyTargetContainer)) { provider.CopyItem(srcPath, destPath, recurse, runtime); return; } // Otherwise we want a flat-hierachy copy of a folder (because copyContainers is CopyChildrenOfTargetContainer) // Make sure recurse is set if (!recurse) { var error = new PSArgumentException("Cannot copy container to existing leaf", "CopyContainerItemToLeafError", ErrorCategory.InvalidArgument).ErrorRecord; runtime.WriteError(error); return; } // otherwise do the flat copy. To do this: get all child names (recursively) and invoke copying without recursion var childNames = ChildItem.GetNames(srcPath, ReturnContainers.ReturnMatchingContainers, true); foreach (var child in childNames) { var childPath = Path.Combine(provider, srcPath, child, runtime); provider.CopyItem(childPath, destPath, false, runtime); } }