问题
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