October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Working with Files Using PowerShell Cmdlets

A practical guide to PowerShell file cmdlets, including recursive listings, file creation, text and byte handling, copying, moving, and safe deletion.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

PowerShell’s FileSystem provider lets you inspect, create, read, write, copy, move, and delete files and folders with cmdlets. For common tasks, use Get-ChildItem to list items, New-Item to create them, Get-Content and the content-writing cmdlets to work with data, and Copy-Item, Move-Item, or Remove-Item to manage paths. The examples below use Windows paths; PowerShell’s item cmdlets are provider-based, so related commands can also operate on items exposed by other providers.

How PowerShell file cmdlets fit together

PowerShell separates work with an item’s path and identity from work with its contents. Item cmdlets manage files and directories; content cmdlets read or write data inside files. The FileSystem provider exposes the local file system, while PowerShell’s provider-based command families can also work with items from other providers.

Task Cmdlet Typical use
Inspect items Get-ChildItem List files and directories, optionally recursively or with filters.
Check a path Test-Path Check whether a path exists before acting on it.
Create an item New-Item Create a file or directory by specifying -ItemType.
Read contents Get-Content Read text lines, a whole file as one string, or bytes.
Replace or append contents Set-Content or Add-Content Replace file contents or add content at the end.
Duplicate or relocate Copy-Item or Move-Item Copy items and trees, or move an item to another path.
Delete items Remove-Item Delete an item; add -Recurse for a directory tree.

How do you list files and folders?

Use Get-ChildItem to list the direct children of a path. Add -Recurse to include descendants, and -Force to include hidden or system items that are otherwise omitted by default in the FileSystem provider.

Get-ChildItem -Path C:Data
Get-ChildItem -Path C:Data -Recurse
Get-ChildItem -Path C:Data -Force

Use -Depth when you want recursion limited to a number of directory levels rather than the full tree. To filter by a property such as file size, retrieve files and pipe them to Where-Object:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
  • Easily store and access 2TB to content on the go with the Seagate Portable Drive, a USB external hard drive
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.
Get-ChildItem C:Data -Recurse -File | Where-Object Length -gt 1MB

PowerShell also provides location cmdlets: Get-Location shows the current location, and Set-Location changes it. Use Test-Path to check whether a path exists before a later copy, write, or delete operation.

How do you create a file or directory?

Specify the item type with New-Item. These commands create a directory and an empty file, respectively:

Rank #2
Seagate Portable 4TB External Hard Drive HDD – USB 3.0, 1-Year Rescue
  • Easily store and access 4TB of content on the go with the Seagate Portable Drive, a USB external hard drive.Specific uses: Personal
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.
New-Item -Path C:TempReports -ItemType Directory
New-Item -Path C:TempReportsrun.txt -ItemType File

The meaning of -Force depends on the target: Microsoft’s examples note that using it for an existing folder returns that folder rather than replacing it, while using it for an existing file overwrites the file. Check the target before using -Force on a file.

How do you read a text file?

Get-Content returns a file’s lines by default. Choose a parameter to read the file in a different way or limit the amount returned:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
  • Easily store and access 1TB to content on the go with the Seagate Portable Drive, a USB external hard drive.Specific uses: Personal
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop. Reformatting may be required for Mac
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.
  • Read lines: Get-Content -Path .log.txt
  • Read the file as one string: Get-Content -Path .log.txt -Raw
  • Read only the last 50 lines: Get-Content -Path .log.txt -Tail 50
  • Read only the first specified number of lines: use -TotalCount.
  • Specify text encoding: use -Encoding when encoding matters.
  • Read bytes: use -AsByteStream rather than treating the data as text.

How do you replace or append file contents?

Set-Content replaces the existing content; Add-Content appends new content. For example, the first command sets the file’s content to Complete, while the second adds Next step to the end:

Set-Content -Path .status.txt -Value 'Complete'
Add-Content -Path .status.txt -Value 'Next step'

Choose the cmdlet based on whether existing content should remain. If the file’s text encoding matters, specify -Encoding.

Rank #4
Sale
Maxone 500GB Ultra Slim Portable External Hard Drive HDD USB 3.0 Compatible with PC, Laptop, Charcoal Grey
  • Ultra Slim and Sturdy Metal Design: Merely 0.4 inch thick. All-Aluminum anti-scratch model delivers remarkable strength and durability, keeping this portable hard drive running cool and quiet.
  • Compatibility: It is compatible with Microsoft Windows 7/8/10, and provides fast and stable performance for PC, Laptop.
  • Improve PC Performance: Powered by USB 3.0 technology, this USB hard drive is much faster than - but still compatible with - USB 2.0 backup drive, allowing for super fast transfer speed at up to 5 Gbit/s.
  • Plug and Play: This external drive is ready to use without external power supply or software installation needed. Ideal extra storage for your computer.
  • What's Included: Portable external hard drive, 19-inch(48.26cm) USB 3.0 hard drive cable, user's manual, 3-Year manufacturer warranty with free technical support service.

How do you copy or move files and folders?

Copy a file or directory tree

Give Copy-Item a source path and destination. Copying a directory tree requires -Recurse:

Copy-Item -Path C:Datareport.csv -Destination C:Backupreport.csv
Copy-Item C:DataProject -Destination C:BackupProject -Recurse

Move or rename an item

Move-Item relocates an item. A destination path with a different name moves and renames it in the same operation:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
YOTUO 500GB External Hard Drive, Portable Storage Expansion HDD, USB 3.0 & USB-C for PC, Mac, Desktop, Laptop, Smartphone, PS4, Xbox One, Xbox 360, Office & Game Black
  • 【Versatile Storage Expansion – For Gaming, Work & Everyday Use】 Running out of space on your PS5 or Xbox Series X/S? This external hard drive lets you store and play PS4 / Xbox One games directly, instantly freeing up your console’s internal storage for next‑gen titles. At the same time, it handles work file backups, media libraries, and cross‑device data transfers with ease. One drive, all your needs. *(Note: PS5 / Xbox Series X|S games cannot be run or stored directly from the external hard drive. However, by offloading your PS4 / Xbox One games, you can free up valuable space for newer titles.)*
  • 【Patented Silicone Sleeve – Data Protection You Can Count On】 Worried about drops? We’ve got you covered. The patented built‑in silicone sleeve acts like a shock‑absorbing armor, cushioning your drive against bumps and falls. Whether it’s important work documents, precious family photos, or hard‑earned game saves, your data deserves this level of protection.
  • 【Plug & Play, Compatible with Computers & Consoles】 No complicated setup—just plug in and go. Works seamlessly with Windows, Mac, and Linux computers, as well as PS4, PS5, Xbox One, and Xbox Series X/S. Process files at the office, back up data at home, or enjoy gaming in your downtime—one drive handles all your devices, simply and hassle‑free.
  • 【USB 3.0 Ultra‑Fast Transfer – No More Waiting】 Tired of watching progress bars crawl? With USB 3.0 speeds up to 5Gbps, large files transfer in seconds. Whether you’re moving work documents, transferring hundreds of gigs of games, or backing up a year’s worth of photos, you get more done in less time.
  • 【Sleek, Lightweight, and Ready to Go】 Weighing just 0.16 kg—lighter than a can of soda—this compact drive features a stylish mirror‑and‑frosted finish. Toss it in your bag and go, whether you’re heading to the office, visiting a friend for a gaming session, or giving a presentation on the road.
Move-Item -Path C:Dataold.txt -Destination C:Dataarchive.txt

An existing destination can cause an operation to fail or require -Force. For a bulk operation, first test the command on a small sample and confirm the destination before applying it broadly.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How do you delete a file or a directory tree?

Delete a single item with Remove-Item. To remove a nonempty directory and its descendants, add -Recurse:

Remove-Item -Path .old.log
Remove-Item -Path C:TempDeleteMe -Recurse

Without -Recurse, removing a directory that contains children can prompt for confirmation. Deleting a tree is consequential, so verify the target path first. Use the common -WhatIf parameter to preview what an operation would do, or -Confirm when you want a confirmation prompt.

What should you check before a bulk file operation?

  • Confirm the current location with Get-Location if you use relative paths.
  • Check that the intended source and destination paths are correct; use Test-Path where existence matters.
  • Review the result of Get-ChildItem before applying a recursive copy or deletion.
  • Use -WhatIf for a preview when appropriate, and test copy or move behavior on a small sample before running it over many items.
  • Use -Force deliberately: it can include hidden items in listings and can overwrite an existing file in relevant operations.

For Microsoft’s procedural examples and parameter details, see Working with files and folders – PowerShell, the about_Core_Commands overview, and the references for Get-ChildItem, Get-Content, Set-Content, Copy-Item, Move-Item, and the FileSystem provider.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick Recap

SaleBestseller No. 1
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$119.99
Bestseller No. 2
Seagate Portable 4TB External Hard Drive HDD – USB 3.0, 1-Year Rescue
Seagate Portable 4TB External Hard Drive HDD – USB 3.0, 1-Year Rescue
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$208.99
Bestseller No. 3
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$119.80

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.