copy-item

Powershell Copy-Item - Access Denied

↘锁芯ラ 提交于 2019-12-11 10:42:22
问题 I'm writing a script that will open files in a directory and perform a find/replace. But before I do that I would like to make copies of the files in the same directory as the original file. All files exist in the C:\Program Files (x86) directory. The script errors out stating that access to the directory is denied. I see that Copy-Item has a -Credential parameter, but on my test machine I don't have any local Administrator permissions. Doesn't seem like there is going to be any way to copy

Powershell Copy-Item caching

瘦欲@ 提交于 2019-12-11 09:27:01
问题 I am having an issue with Powershell not copying the latest files across servers when using the below code. $dir="\\MyServer\SQLBackups\SQL Backup*.bak" $FileLocation = "E:\SQLRestore\SQL Backup Latest.bak" If (Test-Path $FileLocation){ Remove-Item $FileLocation } If (Test-Path $dir){ $latest = Get-ChildItem -Path $dir | Sort-Object CreationTime -Descending | Select-Object -First 1 Copy-Item -Path "$latest" -Destination $FileLocation } The code should locate the latest .bak file with the

Excluding multiple folders when copying using powershell

不羁岁月 提交于 2019-12-11 06:52:25
问题 The objective is to copy folders and files from a path to another path using PowerShell. However, I want to exclude certain files and folders from getting copied. I was able to exclude multiple files by adding them to the exclude list Get-ChildItem -Path $source -Recurse -Exclude "web.config","body.css","Thumbs.db" For excluding folders I added $directory = @("Bin") ?{$_.fullname -notmatch $directory} and the final copy script looks like Get-ChildItem -Path $source -Recurse -Exclude "Web

powershell error checking during file copy with recursion

梦想与她 提交于 2019-12-11 02:25:09
问题 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 recursion" or a better way to do it, so I can enable some kind of error checking during the process rather than after wards. Possibly even do a Test-Path and prompt for a recopy? 回答1: You can. For example the following code snippet will actually copy and check each file for possible errors. You can

Issue with mapping network drives using New-PSDrive

微笑、不失礼 提交于 2019-12-10 22:36:32
问题 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 which runs in each .net task New-PSDrive -Name tid -PSProvider FileSystem -Root \\sname\c$\Users\<Uname>\Appdata\Local\temp\<myapp>\tid -Credential $cred Copy-Item -Source c:\test\* tid:\ Remove-PSDrive -Name tid At any point there could be a bunch of tasks executing this script. Most of the time

Powershell: 'The fully qualified file name must be less than 260 characters'

给你一囗甜甜゛ 提交于 2019-12-10 15:27:32
问题 I tried to use powershell command copy-item as xcopy to copy content of one disk to another one. copy-item -Path h:\* -Destination g:\ -Recurse -Force However, I encountered the following errors: Copy-Item : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. I got these errors enough to discourage manually search and copy files or folders with long paths. What is the best

Powershell Copy-Item Exit code 1

荒凉一梦 提交于 2019-12-10 11:41:38
问题 I have a script with several files I'd like to copy and I do it more or less like so. Copy-Item xxx1 yyy1 -Force Copy-Item xxx2 yyy2 -Force Copy-Item xxx3 yyy3 -Force Copy-Item xxx4 yyy4 -Force and so on. Now I'd like this script to exit with 1 if any of the files was not copied. Thanks in advance 回答1: What you're asking for is similar to the set -e option in bash , which causes a script to exit instantly in the event that a command signals failure (except in conditionals) [1] . PowerShell

Powershell Copy-Item Exit code 1

孤人 提交于 2019-12-07 11:33:25
I have a script with several files I'd like to copy and I do it more or less like so. Copy-Item xxx1 yyy1 -Force Copy-Item xxx2 yyy2 -Force Copy-Item xxx3 yyy3 -Force Copy-Item xxx4 yyy4 -Force and so on. Now I'd like this script to exit with 1 if any of the files was not copied. Thanks in advance What you're asking for is similar to the set -e option in bash , which causes a script to exit instantly in the event that a command signals failure (except in conditionals) [1] . PowerShell has no such option [2] , but you can emulate it: # Set up a trap (handler for when terminating errors occur).

Get the list of files that are getting copied in PowerShell

寵の児 提交于 2019-12-04 23:47:29
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 copy command. Jackie If you just want to see that in console, use the -verbose switch: copy-item -path $from -destination $to -verbose If you want to get a list of files or directories: $files = copy-item -path $from -destination $to -passthru | ?{$_ -is [system.io.fileinfo]} $source=ls c:\temp *.* $i=1 $source| %{ [int]$percent = $i / $source.count * 100 Write-Progress -Activity "Copying ... (

Copy-Item for copy files from local to remove server using credentials

北战南征 提交于 2019-12-02 10:12:58
问题 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 failure: unknown user name or bad password. At line:1 char:10 + Copy-Item <<<< .\copy_test.txt -destination "\\serverip\c$\backups\" -verbose + CategoryInfo : NotSpecified: (:) [Copy-Item], IOException + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.CopyItemCommand I was