$pathname = Read-Host "Please Enter Path Name: "
GCI $pathname -Recurse |
?{$_.LastAccessTime -le (Get-date).AddMonths(-1)} |
Select FullName,CreationTime,LastAccessTime,LastWriteTime |
Export-Csv "c:\$(($pathname -split "\\")[-1]).csv" -NTI
(Get-Date).AddDays(-1) -lt (Get-Date)
$path = 'C:\Source'
$stagingPath = 'D:\Destination'
Push-Location $path
Get-ChildItem $path -Recurse -File |
Where-Object LastAccessTime -le (Get-date).AddMonths(-1) |
ForEach-Object {
$relative = Resolve-Path $_.Directory -Relative
$destination = Join-Path $stagingPath $relative.TrimStart('.')
if (-not (Test-Path $destination)) {
$null = New-Item $destination -ItemType Directory
}
Copy-Item $_.FullName -Destination $destination
}
Pop-Location
Start with that and check the size of everything. If it works, Copy-Item can be change to Move-Item (possibly). Alternatively, we can do one pass to generate the list, archive things, and if that works, delete the items on the list.
$pathname = "C:\Users\kabir.uddin"
$files = Get-ChildItem $pathname -Recurse -File |
Where-Object LastAccessTime -le (Get-date).AddMonths(-1)
foreach ($f in $files)
{
$Name = $f.fullname
#Compress-Archive $f -DestinationPath $path\$Name.zip
}
Open in new window