Как сравнить размер файла для скопированных файлов в PowerShell

Я хочу сравнить размер файлов в папках, которые были скопированы из папки на моем диске D в другую папку, чтобы убедиться, что файлы были скопированы правильно.

Я очень новичок в PowerShell, поэтому, пожалуйста, простите мое невежество. Я пробовал все, чтобы найти ответ на этот вопрос.

$Dest = get-childitem '\\\Path2\\Folder*\\*.csv'
$Source = get-childitem 'D:Path1\\Folder*\\*.csv' 
$DestName = $Dest | Select Name
$SourceName = $Source | Select Name
$Source | ForEach-Object{
    $Source.Length -eq $Dest.Length | where-object {$SourceName -Match $DestName }
 }

person user12004298    schedule 31.08.2019    source источник
comment
взгляните на ››› Get-Help New-FileCatalog ‹‹‹, возможно, это все, что вам нужно.   -  person Lee_Dailey    schedule 01.09.2019


Ответы (1)


попробуй это:

$SourceDir='D:Path1'
$DestinationDir='\\Path2'

$Source = get-childitem "$SourceDir\Folder*" -file "*.csv" -Recurse | select Length, FullName
$Dest = get-childitem "$DestinationDir\Folder*" -file -Filter "*.csv" -Recurse | select Length, @{N='FullName';E={$_.FullName.Replace($DestinationDir, $SourceDir)}}

$Source | ForEach{

$Current=$_
$FileInDest=$Dest | where FullName  -eq $Current.FullName | select -first 1

if ($FileInDest -eq $null)
{
    "File '{0}' not founded in destination dir '{1}'" -f $Current.FullName, $DestinationDir
}
elseif ($Current.Length -ne $FileInDest.Length)
{
    "File '{0}' not same length in destination dir '{1}'" -f $Current.FullName, $DestinationDir
}


}
person Esperento57    schedule 01.09.2019
comment
Там небольшая опечатка: $FileInDest=$Des должно быть $FileInDest=$Dest - person Theo; 02.09.2019