292 questions
101
votes
13
answers
197k
views
Progress during large file copy (Copy-Item & Write-Progress?)
Is there any way to copy a really large file (from one server to another) in PowerShell AND display its progress?
There are solutions out there to use Write-Progress in conjunction with looping to ...
47
votes
2
answers
32k
views
What is the meaning of Powershell's Copy-Item's -container argument?
I am writing a script for MS PowerShell. This script uses the Copy-Item command. One of the optional arguments to this command is "-container". The documentation for the argument states that ...
38
votes
4
answers
45k
views
Get the list of files that are getting copied in PowerShell
I am using the PowerShell Copy-Item command to copy a directory with files to another location.
I want to display all the files on the console that are getting copied so that I know the status of the ...
35
votes
3
answers
44k
views
PowerShell - suppress Copy-Item 'Folder already exists' error
When I run a recursive Copy-Item from a folder that has sub folders to a new folder that contains the same sub folders as the original, it throws an error when the subfolders already exist.
How can I ...
33
votes
5
answers
75k
views
Powershell Copy-Item but only copy changed files
I am trying to recurse through a directory and copy it from A to B. That can be done with the following:
Copy-Item C:\MyTest C:\MyTest2 –recurse
I want to be able though to only copy new files (ones ...
21
votes
3
answers
58k
views
Need help on Powershell Copy-Item from network drives
I am trying to use Copy-Item from remote machine to another remote machine with the command:
Copy-Item -Path "\\machine1\abc\123\log 1.zip" -Destination "\\machine2\\c$\Logs\"
I am constantly getting ...
19
votes
1
answer
28k
views
Powershell 3.0: COPY-ITEM Filter or Include options not working
Does the -Filter or -Include parameter work for anyone when using Powershell 3.0? I've tried both of the following commands:
Copy-Item -Path c:\temp -Include "*.TXT" -Destination C:\temp2
and
Copy-...
16
votes
1
answer
34k
views
PowerShell use xcopy, robocopy or copy-item [closed]
The reason for switching from batch files to powershell scripts is to improve error checking of the process. Does the cmdlet for copying have advantages in this regard?
If a batch file already ...
15
votes
5
answers
48k
views
Get-ChildItem and Copy-Item explanation
Why does
gci $from -Recurse | copy-item -Destination $to -Recurse -Force -Container
not behave in the same way as
copy-item $from $to -Recurse -Force
?
I think it should be the same, but somehow ...
8
votes
2
answers
4k
views
PowerShell copy fails without warning
Howdy, am trying to copy a file from IE cache to somewhere else. This works on w7, but not Vista Ultimate.
In short:
copy-item $f -Destination "$targetDir" -force
(I also tried $f.fullname)
The ...
8
votes
3
answers
28k
views
Want to wait till copy complete using Powershell Copy-Item
I am copying files from One Windows machine to another using Copy-Item in Powershell script.
But I want to wait till copy completes, Powershell Copy-Item is non-blocking call means, it just triggers ...
7
votes
1
answer
500
views
Copy-Item inconsistent behavior?
Consider this directory structure:
C:\temp\A\file.txt
C:\temp\B
If I run the command
Copy-Item "C:\temp\A" "C:\temp\B\A" -Recurse -Force -ErrorAction Stop
I have
C:\temp\A\file.txt
C:\temp\B\A\...
6
votes
2
answers
26k
views
PowerShell: Copy-Item Cannot find path
I'm trying to get PowerShell to copy files from a remote computer (on which I have admin rights through AD) to the local computer.
It fails in the strangest place. Here's a snippet of the script:
...
6
votes
2
answers
10k
views
Copy-Item when destination folder exists or doesn't
When destination folder exists the right way of copying files is defined here
Copy-Item 'C:\Source\*' 'C:\Destination' -Recurse -Force
If destination folder doesn't exist, some files in the source ...
6
votes
4
answers
15k
views
How Do I copy the files and the Folder Tree to Remote Machine?
I have two machines Server A and Server B, and I want to copy all the files and folder tree from Server A to Server B using PowerShell.
I have tried the command given below, but it copies only the ...
4
votes
2
answers
11k
views
Powershell: 'The fully qualified file name must be less than 260 characters'
I tried to use powershell command copy-item as xcopyto copy content of one disk to another one.
copy-item -Path h:\* -Destination g:\ -Recurse -Force
However, I encountered the following errors:
...
4
votes
1
answer
2k
views
Copying a file on change using PowerShell
I am using a FileSystemWatcher to notify on file change, and then create a copy of that file:
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "C:\Orders\"
$watcher....
4
votes
1
answer
16k
views
powershell error checking during file copy with recursion
I have a program that copies folders and files recursively.
example:
Copy-Item -path "$folderA" -destination "$folderB" -recurse
Sometimes the files do not copy. Is there a way to "step inside the ...
4
votes
2
answers
2k
views
Copy-Item copies folder inside the target when running second time
During repetitive logs collection on my internal system, found strange behavior of recursive Copy-Item call
Say, i have C:\Source with some files and subfolders with files. I want to copy this ...
4
votes
2
answers
13k
views
How to force the copy of a file using powershell
I'm using powershell to copy file to a remote computer witht he following command :
Copy-Item -Path [MyPath]\* -Destination \\[server]\[MyPath] -force
It's working great, but sometime I'm receiving ...
4
votes
1
answer
552
views
PowerShell: Copy-Item within PSSession ignores -Filter -Include -Exclude
Using the PowerShell command Copy-Item to copy files works fine locally, but when running it in a PSSession, the options -Filter, -Include and -Exclude show no effect while copying files from the ...
4
votes
1
answer
832
views
Solution for copying files between windows machines using different credentials
I work on a windows service application which can run scripts on a target machine. One of things I need to do is copy files over from my host machine to the target machine for different users. I have ...
4
votes
5
answers
13k
views
Copy-Item Could not find part of path (with . in folder name)
I'm trying to use Copy-Item to copy a file to an existing folder and getting the error "Could not find part of path". I've Googled this problem for ages, but can't seem to find an answer.
I altered ...
3
votes
2
answers
6k
views
Copy (append) multiple files into a single destination file
I'm having a weird issue with using PowerShell to merge multiple csv files into one. I've done this plenty of time in the cmd prompt on in windows 7, but here the output only contains the earliest ...
3
votes
1
answer
3k
views
Passing the current File Path through to Powershell "SendTo" Script
I'm trying to create a script that will let me copy an item from one location to a specified location in a PowerShell script. Before it's mentioned, I know that I can put a shortcut in the Send To ...
3
votes
1
answer
17k
views
Powershell script to create folders from list of names in a file
I have a text file that contains a list of files in different directories, e.g
C:\FolderOne\Testing.jpg
C:\FolderTwo\Test.jpg
I'd like to turn those names into folders. And if two files exist in one ...
3
votes
1
answer
3k
views
Copying files and creating new folders based on "creationdate"
I am counting all files in my Pictures folder with
Get-ChildItem C:\pictures -force | Group-Object extension | Sort-Object count -descending | ft count,name -auto
I am then copying all my MTS-files (...
3
votes
1
answer
1k
views
Issue in Copy-Item in powershell
I used the Copy-Item command to copy a set reports to a server location. It was working fine before but recently more reports have been added to the folder and now most of the times it works fine but ...
3
votes
2
answers
5k
views
Issue with mapping network drives using New-PSDrive
I am running a powershell based multithreaded application in which each thread (.net task) needs to copy a bunch of files from one machine to another with a different credential.
This is the script ...
3
votes
1
answer
1k
views
Odd Copy-Item powershell behaviour
I'm still a bit of a newbie at powershell (coming from vbscript) and it has been a while since I have done anything too serious, so I apologise in advance if the code isn't as graceful as it could be.
...
2
votes
2
answers
9k
views
Swift 3: Error in copying file with FileManager
I have a file named Data.plist in my main bundle (at the root of the app directory), and I am trying to copy this file to user document directory for read and write operations, however, I got the ...
2
votes
2
answers
9k
views
PowerShell: Copy-Item throws DriveNotFoundException
My script keeps bugging me with the following exception
copy-item : Cannot find drive. A drive with the name 'F' does not exist.
At C:\Program Files (x86)\CA\ARCserve Backup\Templates\RB_Pre_Process....
2
votes
4
answers
4k
views
Copy-Item not including subfolder files of source directory in PowerShell
I have a script which moves files with a specific extension from a source directory to a destination directory.
My source directory looks like:
FILESFOLDER
File1.td
File2.td
SUBFOLDER
File3.td
...
2
votes
2
answers
12k
views
Copy-Item Failing Given Paths format is not supported
This is driving me bananas. I am assuming I am missing something stupid, but I have tried about 10 different formats and nothing works.
This is the code I am running:
$today=$(Get-Date -Format o)
$...
2
votes
1
answer
4k
views
copy-item a file with strange characters in filename (i.e [])
I must copy a file names as follow
$filename = "Sport.EL#15.csv.[]"
into another folder.
if I use
copy-item -force Sport.EL#15.csv.[] $dest_path
it doesn't work.
since I do that:
foreach ...
2
votes
2
answers
1k
views
How to pipe directly to Copy-Item instead of within a ForEach-Object
Because the -Exclude parameter of Get-ChildItem is not filtering on subfolders when using the -Recurse flag, see among other unable-to-exclude-directory-using-get-childitem-exclude-parameter-in-
...
2
votes
4
answers
19k
views
Powershell Copy-Item - Exclude only if the file exists in destination
Following is the exact scenario in my powershell script.
$Source = "C:\MyTestWebsite\"
$Destination = "C:\inetpub\wwwroot\DemoSite"
$ExcludeItems = @(".config", ".csproj")
Copy-Item "$Source\*" -...
2
votes
1
answer
4k
views
PowerShell Copy-Item what I'm doing wrong?
Given the dir structure:
x\Code
x\Script\Backup.ps1
Backup.ps1 contains:
$BackupDirectoy = "..\Backup"
$CodeDirectory = "..\Code"
function BackupCurrentVersion()
{
New-Item $...
2
votes
1
answer
3k
views
Copy-item using invoke-async in Powershell
This article shows how to use Invoke-Async in PowerShell: https://sqljana.wordpress.com/2018/03/16/powershell-sql-server-run-in-parallel-collect-sql-results-with-print-output-from-across-your-sql-farm-...
2
votes
1
answer
73
views
Pipelined copy-item doesnt work after a file is renamed
I am quite new to PowerShell.
I have created a PowerShell script which identifies a specific Mp3 file out of a large number of very similar files in one folder based on certain criteria:
Is the most ...
2
votes
1
answer
3k
views
Powershell copying specific files from all subfolders to a single folder
I'm trying to copy all of the cover.jpg files in my music library to one folder. My attempts so far have either landed me with one file in the destination, or every desired file but also in their own ...
2
votes
2
answers
276
views
[Powershell]: 2nd Execution of Copy-Item creates subfolder (5.1.17763.1007)
After searching for a wile I need to post my question here:
I want to do a simple task:
copy-item -path "C:\Folder Copied" -destination "C:\Folder Copied_New" -recurse
Assuming ...
2
votes
2
answers
4k
views
Copy-item using Start-ThreadJob in Powershell
Off the back of this thread: Copy-item using invoke-async in Powershell I have the following:
@mklement0's method (Copied from and amended by from here) works, but because it creates a thread per-...
2
votes
1
answer
154
views
Powershell Copy-Item destination is ambiguous
Assuming that "C:\Temp\first.txt" is a file, is there some way to ensure that
Copy-Item -Path "C:\Temp\first.txt" -Destination "C:\Temp\second.txt"
creates file "C:\Temp\second.txt", or else fails? ...
2
votes
2
answers
9k
views
How To copy only new files from one folder to another with PowerShell
I'm having a little trouble finishing a powershell script. I have a program that downloads images into a temporary folder, then within an hour it will delete the image files. Occasionally I would ...
2
votes
1
answer
9k
views
Copy-Item from New-PSDrive within PSSession
I have the following Powershell code:
Enter-PSSession -ComputerName test01
New-PSDrive -Name Source -PSProvider FileSystem -Root \\test02\SMBTest -Credential test\Administrator
Copy-Item Source:\...
2
votes
3
answers
8k
views
Copy-Item for copy files from local to remove server using credentials
I am trying to copy some files and folder from my local machine to a remote server:
Copy-Item .\copy_test.txt -destination "\\serverip\c$\backups\"
but I'm getting an error:
Copy-Item : Logon ...
2
votes
1
answer
2k
views
In Powershell can you use the copy-item command to copy all the contents of a directory including folders?
I know how to do it with different commands but is there a way to make it so copy-item cmdlet also copies directories to the target folder for example if I wanted to copy everything in the C:\users ...
2
votes
1
answer
364
views
Copy select items from one folder to a new folder
I am getting all wav files in the past 24 hours from one folder and putting them in another folder. I swear this worked for me a bit ago and wanted to add in some more conditional statements but now ...
2
votes
1
answer
14k
views
Powershell Test-Path and If statement, executes both if and else statements
I'm doing a few small school assignments, but our teacher is doing a pretty bad job in explaining stuff, so I've basically just been googling watching videos etc.
But I have to make a script that ...