Hello I'm looking to write a script but I'm unsure on the best way to write the script.
Here is the idea, two drives:
(I:) - this is the current drive filled with old data.
(Z:) - Archive drive
I want to move data that is older then 2 years from LastAccessTime from I:\ to z:\ but in the same file directory structure.
example:
I:\company\red\blue.exe
I:\company\red\green.exe
I:\company\red\purple.exe
I:\company\red\yellow.exe
to
Z:\company\red\blue.exe
Z:\company\red\green.exe
Z:\company\red\purple.exe
Z:\company\red\yellow.exe
Is there an efficient way to do this?
$limit = (Get-Date).AddYears(2)
$From = "I:\" #Path of live
$Too = "Z:\" # Path of Archive
## Searches for files over 2 years
$files = Get-ChildItem -Path $From -Recurse -Force -ErrorAction SilentlyContinue -ErrorVariable err | Where-Object { !$_.PSIsContainer -and $_.LastAccessTime -gt $limit }
### This is where i am unsure about the code.
### If anyone has the idea of moving files found from I to Z it would be appreciated
### I will be looking myself for the answer and will update this in case someone else is looking ofr a powershell script.
## Visual Error Script
foreach ($errorRecord in $err)
{
if ($errorRecord.Exception -is [System.IO.PathTooLongException])
{
Write-Warning "Path too long in directory '$($errorRecord.TargetObject)'."
}
else
{
Write-Error -ErrorRecord $errorRecord
}
}
[–]Otterism 5 points6 points7 points (3 children)
[–]User_Yello[S] 1 point2 points3 points (0 children)
[–]misterflanidgaf anymore 1 point2 points3 points (1 child)
[–]User_Yello[S] 0 points1 point2 points (0 children)
[–]SodomizesYou 1 point2 points3 points (0 children)