I’m was thinking of using If…Else construct in way like:
If Archive folder exists and if there is some patients to archive then just do it
Else if folder doesn’t exists then create it and archive patients there
Else if folder exists and it’s no patients to archive just don’t do anything.
Problem is…I just don’t know how to do this. A little thought about that:
$Source = 'C:\Vitrea\Patients'
$Destenation = 'D:\PatientsArchive'
$Date = (Get-date.AddDays(-31))
$Directory = Get-ChildItem $Source -Recurse | Where {$_.CreationTime -lt $Date}
if(Test-Path $Destenation){
Write-Host "Archiving now"
Move-Item -Path $Directory -Destination $Destenation
}#End if
Elseif(Test-Path $Destenation){
New-Item -ItemType Directory -Path $Destenation
Move-Item -Path $Directory -Destination $Destenation
}#End elseif
Else{
Write-Host "Nothing to archive"
}# end Else
[/PRE]
Any help would be greatly appreciated
I’m not quite sure how foreach must looks in this script. I will put my suggestion down below because you are right: $Directory is a folder that contains subfolders which contains DICOM-Images. Also thank you for all your tips about brackets and conditions.