Reputation: 1
Tried to copy several files (newer version) from one location to several different locations (older version) based on search result. The search and rename worked fine; but copy didn't work. Just need a way to point the current search directory as -destination folder.
Script used -
Get-ChildItem C:\, D:\ -include '*db2jcc*' -Recurse -ErrorAction SilentlyContinue |
Where-Object { $_.LastWriteTime -lt '2018-05-02' } |
Rename-Item -NewName { $_.name -replace 'DB2JCC','Old_DB2JCC' }
ForEach-Object { Copy-Item 'C:\Program Files\IBM\SQLLIB\java\DB2JCC*.*' -Destination $ENV:Temp }
Any help or suggestion will be appreciated.
Thanks, Johnson
Upvotes: 0
Views: 94
Reputation: 4694
Based off your answer, you can try something a long the lines of this:
[System.Collections.ArrayList]$Paths = @()
Get-ChildItem C:\,D:\ -Filter "*db2jcc*" -Recurse -ErrorAction SilentlyContinue |
Where-Object { $_.LastWriteTime -lt '2018-05-02' } | ForEach-Object -Process {
$null = $Paths.Add($_.FullName)
Rename-Item -Path $_.FullName -NewName $_.Name.Replace('DB2JCC','Old_DB2JCC') -ErrorAction SilentlyContinue }
Foreach($Path in $Paths){
$Path = $Path -replace '[^\\]+$'
Copy-Item "C:\Program Files\IBM\SQLLIB\java\" -Filter "DB2JCC*" -Recurse -Destination $Path }
Upvotes: 0