
XCOPY, ROBOCOPY, and COM objects, suchĪs the Scripting.FileSystemObject, all work in Windows PowerShell. You can still use other tools to perform file system copies. txt files containedĪnywhere in C:\data to C:\temp\text: Copy-Item -Filter *.txt -Path c:\data -Recurse -Destination C:\temp\text This command copies the folder C:\temp\test1 to the new folderĬ:\temp\DeleteMe recursively: Copy-Item C:\temp\test1 -Recurse C:\temp\DeleteMe This command works even when the destination is read-only.įolder copying works the same way. To overwrite a pre-existingĭestination, use the Force parameter: Copy-Item -Path C:\boot.ini -Destination C:\boot.bak -Force If the destination file already exists, the copy attempt fails. The following command backs up C:\boot.ini to C:\boot.bak: Copy-Item -Path C:\boot.ini -Destination C:\boot.bak The following command finds all executables within the Program Files folder that were last modifiedĪfter Octoand which are neither smaller than 1 megabyte nor larger than 10 megabytes: Get-ChildItem -Path $env:ProgramFiles -Recurse -Include *.exe | Where-Object -FilterScript Ĭopying is done with Copy-Item. Other properties of items by using Where-Object. You can perform complex filtering based on Parameters, but those are typically based only on name. Get-ChildItem can filter items with its Path, Filter, Include, and Exclude (This can take an extremely long time to complete.) To list everything on the Cĭrive: Get-ChildItem -Path C:\ -Force -Recurse In order to show contained items, you need to specify the -Recurse The command lists only the directly contained items, much like using Cmd.exe's DIR command or For example, this command displays the directĬontents of Windows PowerShell Drive C (which is the same as the Windows physical drive C): Get-ChildItem -Path C:\ -Force Add the optionalįorce parameter to display hidden or system items. You can get all items directly within a folder by using Get-ChildItem. Listing All the Files and Folders Within a Folder With specific file and folder manipulation tasks using PowerShell. Manipulating files and folders on Windows physical disk drives. Navigating through Windows PowerShell drives and manipulating the items on them is similar to
