-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGCI_ThreeMonthsPrior.psi
More file actions
24 lines (22 loc) · 1.01 KB
/
Copy pathGCI_ThreeMonthsPrior.psi
File metadata and controls
24 lines (22 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<# some elements are missing on purpose #>
$threeMonthsPrior = ((Get-Date -Day 1 -Month (Get-Date).Month -Year (Get-Date).Year -Hour 0 -Minute 0 -Second 0).AddMonths(-3)).AddDays(-1)
$source = "\\remote_file_server\c$\directory_to_scan"
$gciDirectoryListing = Get-ChildItem $source | Where {$_.CreationTime -lt $threeMonthsPrior -and $_.Attributes -eq "Directory" -and $_.BaseName -ne "Archive"}
$timestamp = Get-Date -Format o | foreach {$_ -replace ":", "."}
foreach ($item in $gciDirectoryListing)
{
$item.FullName
$fullName = $item.FullName
$item.CreationTime
$creation = (Get-Date $item.CreationTime).AddMonths(-1)
$creation
$creationYear = $creation.Year
$creationYear
$creationMonth = $creation.Month
$creationMonth
$destination = "$source\Archive\$creationYear\$creationMonth\"
$destination
Add-Content $logfile "$timePrint : Moving: $fullName "
Add-Content $logfile "$timePrint : Destiation: $destination"
Move-Item -Path $item -Destination $destination -Force
}