PowerShell: Copy/Move Files based on a regex value, retaining the folder structure, etc
The first one should ideally work. It does preserve the directory structure. But you have to be careful about copying folders. Assuming you want just the files in the pattern that you want in and you don't care about the folders being there, you can do below:
$source = "W:\IIS"
$destination = "C:\Temp\DevTest"
if(-not (Test-Path $destination)) { mkdir $destination | out-null}
foreach ($i in Get-ChildItem -Path $source -Recurse)
{
if (($i.Name -notmatch "_\d{8,10}$") -and (-not $i.PsIsContainer))
{
continue;
}
Copy-Item -Path $i.FullName -Destination $i.FullName.Replace($source,$destination).Trim($i.Name)
}