Isso só irá recursivamente olhar sua pasta recursivamente na raiz que você digita no código.
Espero que você comece. Eu não entendo os requisitos para o resto da questão, no entanto.
$looking_for = "*.ini" # extension looking for
$path_from = "" # root of search;
$path_to = "" # where to drop found files, wont retain folder heirarchy;
$all_files_in_dir = Get-ChildItem -path $path_from -recurse -Include
$looking_for | ForEach-Object -Process {$_.FullName};
New-Item -ItemType Directory -Force -Path $path_to # Create dest for you files
Foreach ($i in $year) { ## create your year folders
$p = Join-Path $path_to $i
New-Item -ItemType Directory -Force -Path $p
}
foreach( $i in $all_files_in_dir ) {
if ( $i -like $looking_for ) {
Copy-Item $i $path_to
if ( $? ) { # was last command succsesful?
echo "$i copied to $path_to
}
}
else {
echo "ERROR: "
throw $error[0].Exception
}
}
}