---
title: "Copy Files Efficiently with PowerShell Copy-Item: A Comprehensive Guide"
description: "Learn how to copy files using the Copy-Item cmdlet, allowing you to copy files, recurse through directories, and use wildcards to select specific files."
canonical: "https://adamtheautomator.com/copy-item/"
---

# Copy Files Efficiently with PowerShell Copy-Item: A Comprehensive Guide

> Learn how to copy files using the Copy-Item cmdlet, allowing you to copy files, recurse through directories, and use wildcards to select specific files.

Source: https://adamtheautomator.com/copy-item/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Copy Files Efficiently with PowerShell Copy-Item: A Comprehensive Guide](https://adamtheautomator.com/wp-content/uploads/2019/06/copy-item-copying-files-powershell-copy-item.jpeg)

# Copy Files Efficiently with PowerShell Copy-Item: A Comprehensive Guide

[![](https://secure.gravatar.com/avatar/d0b9d42e21e5622713f8b693aa5c0f9244d5f7dd200ed29b8398f52dee5de337?s=192&d=mm&r=g)Adam Bertram](https://adamtheautomator.com/author/adam-bertram/)16 June 20194 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PowerShell](/tag/powershell/)

Table of Contents

*   [Basic Usage](#basic-usage)
*   [Getting Selective with Copy-Item](#getting-selective-with-copy-item)
*   [Merging Multiple Folders Together](#merging-multiple-folders-together)
*   [Copying Files Recursively](#copying-files-recursively)
*   [Advantages of using the PassThru Parameter](#advantages-of-using-the-passthru-parameter)
*   [Copying Files Using a PowerShell Remoting Session](#copying-files-using-a-powershell-remoting-session)
*   [Summary](#summary)
*   [Further Reading](#further-reading)

Copying files. It’s not sexy but has to be done. In the GUI, we copy and paste with the clipboard but in PowerShell we have a cmdlet called Copy-Item.

Commands for copying files have been around forever in all shell languages. In PowerShell land, the most popular way to get a copy of a file or folder in your PowerShell script from point A to point B is by using the PowerShell `Copy-Item` cmdlet. This cmdlet allows us to copy a file and folder while giving us the ability to recurse files in a folder, use wildcards to select the files we need to copy and even use [PowerShell Remoting](https://adamtheautomator.com/psremoting/ "PowerShell Remoting") for a file copy!

Th`is` cmdlet is a part of the [PowerShell provider](https://msdn.microsoft.com/en-us/library/ee126186\(v=vs.85\).aspx) cmdlets. It’s a generic cmdlet that recognized by its _Item_ noun. Most of these provider cmdlets can be used across different providers but in my nearly 10 years of using PowerShell, I’ve only seen `Copy-Item` to be used with the file system provider.

By using `this cmdlet` PowerShell allows a developer to copy files and folders a number of different ways.

## Basic Usage

At it’s most basic, the `Copy-Item` cmdlet copies a single file from point A to point B using the `Path` parameter as the source file path and the `Destination` parameter as the destination folder path.

```powershell
PS> Test-Path -Path C:\PointB\1.txt
False
PS> Copy-Item -Path C:\PointA\1.txt -Destination C:\PointB\
PS> Test-Path -Path C:\PointB\1.txt
True 
```

This cmdlet can also copy empty folders as well. I’ll list item in the _C:\\EmptyFolder_ folder and then copy those out.

```powershell
PS> Get-ChildItem -Path C:\EmptyFolder\
PS> Test-Path -Path C:\PointB\EmptyFolder -PathType Container
False
PS> Copy-Item -Path C:\EmptyFolder\ -Destination C:\PointB\
PS> Test-Path -Path C:\PointB\EmptyFolder -PathType Container
True 
```

Perhaps there is a read-only file in the folder. By default, `Copy-Item` will not overwrite it. To force the override, just add the `Force` parameter.

## Getting Selective with Copy-Item

In addition to copying a single file or folder, we can also copy the entire contents of a folder. The `Path` parameter of Copy-Item accepts wildcard characters like the asterisk to match one or more characters or the question mark to only match a single character.

```powershell
PS> @(Get-ChildItem -Path C:\PointB).Count
0
PS> @(Get-ChildItem -Path C:\PointA).Count
10000
PS> @(Get-ChildItem -Path C:\PointB).Count
0
PS> Copy-Item -Path C:\PointA\* -Destination C:\PointB\
PS> @(Get-ChildItem -Path C:\PointB).Count
10000
PS> @(Get-ChildItem -Path C:\PointB).Count
0
PS> Copy-Item -Path 'C:\PointA\26?0.txt' -Destination C:\PointB\
PS> Get-ChildItem -Path C:\PointB\

Directory: C:\PointB
Mode                LastWriteTime         Length Name
-a----        8/11/2017   8:59 AM              5 2600.txt
-a----        8/11/2017   8:59 AM              5 2610.txt
-a----        8/11/2017   8:59 AM              5 2620.txt
-a----        8/11/2017   8:59 AM              5 2630.txt
-a----        8/11/2017   8:59 AM              5 2640.txt
-a----        8/11/2017   8:59 AM              5 2650.txt
-a----        8/11/2017   8:59 AM              5 2660.txt
-a----        8/11/2017   8:59 AM              5 2670.txt
-a----        8/11/2017   8:59 AM              5 2680.txt
-a----        8/11/2017   8:59 AM              5 2690.txt
```

## Merging Multiple Folders Together

Another cool feature of `Copy-Item` is it’s ability to copy multiple folders together at the same time. By passing multiple paths to the `Path` parameter, `Copy-Item` will look at each one, copy either the folder or file(s) depending on the path and “merge” them all into the single destination.

```powershell
PS> Copy-Item -Path C:\PointB\*,C:\PointC\*,C:\PointD\* -Destination C:\PointE
PS> Get-ChildItem -Path C:\PointE

Directory: C:\PointE
Mode                LastWriteTime         Length Name
-a----       11/11/2017  12:15 PM              2 PointBFile.txt
-a----       11/11/2017  12:15 PM              2 PointCFile.txt
-a----       11/11/2017  12:16 PM              4 PointDFile.txt
```

## Copying Files Recursively

Chances are you’re not going to get lucky and have all files in a single folder with no folders in there as well. We usually run into situations where we’ve got lots of subfolders in the parent folder which files in them too we’d like to copy over. By using the `Recurse` parameter on `Copy-Item`, it will gladly look in each subfolder and copy all files and folders in each recursively.

Notice here that I’m piping files and folders from `Get-ChildItem` directly to `Copy-Item`. `Copy-Item` has pipeline support!

```powershell
PS> (Get-ChildItem -Path C:\PointB\ -Recurse).Count
5
PS> Get-ChildItem -Path C:\PointB\ | Copy-Item -Destination C:\PointC -Recurse
PS> (Get-ChildItem -Path C:\PointC\ -Recurse).Count
5
```

## Advantages of using the PassThru Parameter

Many cmdlets in PowerShell have a PassThru parameter. Cmdlets that typically return nothing can return the objects they are manipulating using the PassThru parameter. This cmdlet is no different. When I first started scripting, I never used this parameter because I didn’t feel I needed to.

For example, if I wanted to copy a file to a remote location and then reference that file later on in my script I’d do something like this:

```powershell
$remoteFilePath = '\WEBSRV1\c$\File.txt'
Copy-Item -Path C:\File.txt -Destination $remoteFilePath
Write-Host "I've just copied the file to $remoteFilePath"
```

This method works but it can be better. Instead of defining a variable for the remote path, why not just capture the object that gets returned from `Copy-Item` cmdlet when using the `PassThru` parameter instead? The objects returned will always have the destination file path.

```powershell
$copiedFile = Copy-Item -Path C:\File.txt -Destination '\WEBSRV1\c$'
```

## Copying Files Using a PowerShell Remoting Session

One cool feature that came with PowerShell v5 is this cmdlet’s ability to not use the default SMB protocol for transferring a file but instead use WinRM and a PowerShell remote session. By using the `Session` parameter, `Copy-Item` uses an existing PowerShell session and transfers the files that way. This is a great way to get around firewalls and when the session communication is encrypted, an extra layer of security as well.

```powershell
PS> $session = New-PSSession -ComputerName WEBSRV1
PS> Invoke-Command -Session $session -ScriptBlock { Test-Path -Path C:\File.txt }
False
PS> Copy-Item -Path C:\File.txt -ToSession $session -Destination 'C:\'
PS> Invoke-Command -Session $session -ScriptBlock { Test-Path -Path C:\File.txt }
True
```

We _could_ have copied the File.txt file over SMB and hoped the _C$_ admin share was available and used the destination path of `\\WEBSRV1\c$`. Since we used the `ToSession` parameter instead, the destination path will always be the path local to the computer the remote session is running under.

## Summary

The `Copy-Item` cmdlet is one of those core PowerShell cmdlets that you’ll use over and over again. In PowerShell, copy files, folders in a number of different ways with it’s simple yet powerful especially with its ability to use wildcards, to merge multiple folders of files together and to use existing PowerShell Remoting sessions!

## Further Reading

*   **_[The Ultimate Guide To Robocopy](https://adamtheautomator.com/robocopy/)_**

![Copy-item](https://adamtheautomator.com/wp-content/uploads/2022/08/Copy-item-1024x576.jpg)

Copy-item

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fcopy-item%2F&text=Copy%20Files%20Efficiently%20with%20PowerShell%20Copy-Item%3A%20A%20Comprehensive%20Guide)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fcopy-item%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fcopy-item%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/06/26995-troubleshoot-dns-issues-powershell-codex.webp)

### [Troubleshoot DNS Issues with PowerShell](/troubleshoot-dns-issues-powershell/)

Troubleshoot DNS issues with PowerShell by testing name resolution, DNS client settings, cache entries, and network connectivity in a repeatable workflow.

![](https://adamtheautomator.com/wp-content/uploads/2025/10/image_2025-10-24_095322075.png)

### [Migrating from PowerShell 6 to 7.5: Breaking Changes/New Features](/migrating-powershell-6-to-7-5/)

Migrate from PowerShell Core 6 to 7.5: breaking changes, features, and testing tips.

![](https://adamtheautomator.com/wp-content/uploads/2025/06/featured-image-6.png)

### [How to Add Timeouts to Pester Tests with PowerShell Runspaces](/pester-test-timeout-runspaces/)

Prevent Pester tests from hanging indefinitely using PowerShell runspaces. Learn to handle variable scoping, module loading, TestDrive access, and stream capture challenges with timeout protection.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
