Você está colocando o índice incorretamente. Experimente:
$csv1[$count].filecount -= $csv2[$count].filecount
$csv1[$count].FolderSize-= $csv2[$count].FolderSize
Ou crie um novo CSV3
## Q:\Test18\SU_1327671.ps1
#Importing CSV files
$CSV1 = Import-Csv -Path "D:\test\folderstat1.csv"
$CSV2 = Import-Csv -Path "D:\test\folderstat2.csv"
#Setting counts for do loop
$end = $csv1.Count
$count = 0
#Set $CSV3 Filecount and foldersize to the difference between the row in CSV1 #and CSV2
$CSV3 = do{
[PSCustomObject]@{
Directory = $csv1[$count].Directory
Filecount = ($csv1[$count].filecount - $csv2[$count].filecount)
FolderSize= ($csv1[$count].FolderSize - $csv2[$count].FolderSize)
}
$count++
} until($count -eq $end)
$CSV3 | Export-Csv "D:\test\out.csv" -NoTypeInformation
"=" * 50
$CSV3 | Sort {[Math]::Abs($_.FolderSize)} -Desc | Select -First 1|
ForEach{"Largest (absolute) change {0} in {1}" -f $_.FolderSize,$_.Directory}
Exemplo de saída:
> . .\SU_1327671.ps1
==================================================
Largest (absolute) change 5296 in D:\test\Media
> import-csv .\out.csv
Directory Filecount FolderSize
--------- --------- ----------
D:\test\Documents 0 0
D:\test\Media 2 5296
D:\test\Photos 21 1,37