Copy rename move files powershell

拜拜、爱过 提交于 2021-01-29 12:32:05

问题


After a short period of time I managed to create a script that copies from one server to another, after that it renames it with date and time and then it should move the files to another location. I keep getting an error, and I am not entirely sure what is happening

$server2 = "C:\Users\nicolae.calimanu\Documents\A\"  # UNC Path. 
$datetime = Get-Date -Format "MMddyyyy-HHmmss"
$server3 = "C:\Users\nicolae.calimanu\Documents\C\" # UNC Path. 
foreach ($server1 in gci $server1  -recurse)
 { 
     Copy-Item -Path $server1.FullName -Destination $server2
 }

 ForEach ( $server2 in $server2 ) {
    $curDateTime = Get-Date -Format yyyyMMdd-HHmmss
    Get-ChildItem $server2  -Recurse | 
    Rename-Item -NewName {$_.Basename + '_' + $curDateTime + $_.Extension }
   }

foreach ($server2 in gci $server2 -Recurse)
 { 
     Move-Item -path $server2 -destination "C:\Users\nicolae.calimanu\Documents\C"
 }

error is " Move-Item : Cannot find path 'C:\WINDOWS\system32\test.csv_20200513-132035.xlsx' because it does not exist. At line:17 char:6 + Move-Item -path $server2 -destination "C:\Users\nicolae.calimanu ..."

Any ideas?

来源:https://stackoverflow.com/questions/61773337/copy-rename-move-files-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!