Author Posts

August 7, 2017 at 11:10 pm

Hi there
i have a code which compares 3 "states" of a user mailbox size
initial(from a csv)
start(quick live run based on list)
finish(quick run based on list 5 sec after)
i am running them concurrently using invoke-all to save time using jobs.
i am not sure i am even using the right approach since the list gets unsorted(i think) which makes the compare not work right
so i tried using sort but im still not it compares the right data from the same user in all 3 "phases".
bottom line is i have 3 "lists" of data that i need to compare the same unique user on and see what the differences are and report/store based on that(did the size increase or not...)
heres the code if anyone has an idea or better way to do it:

$s=import-csv c:\files\users.csv |Sort-Object displayname -Descending
$s1=import-csv c:\files\users.csv |Invoke-All {Get-MailboxStatistics -Id $_.displayname} -Force |Sort-Object displayname -Descending
Start-Sleep 5
$s2=import-csv c:\files\pilot0sizebefore.csv |Invoke-All {Get-MailboxStatistics -Id $_.displayname} -Force|Sort-Object displayname -Descending
$Finished=@()
$Notfinished=@()
foreach ($i in $s){
Write-Host "Working on $($i.displayname)" -ForegroundColor Yellow
$1=$i.TotalItemSize
foreach ($j in $s1){
Write-Host "Working on $($j.displayname)" -ForegroundColor Yellow
$2=$j.TotalItemSize
foreach ($n in $s2){
Write-Host "Working on $($n.displayname)" -ForegroundColor Yellow
$3=$n.TotalItemSize
$1
$2
$3

if($1 -eq $2){write-host $($i.displayname) -ForegroundColor red "Restore Started"}
if ($2 -eq $3){write-host $($i.displayname) -ForegroundColor green "Restore Ended";$Finished+=$i}
else {$Notfinished+=$i}

}}}

any help would be greatly appreciated
Thanks

August 8, 2017 at 2:34 pm

small update,disregard the invoke-all parts,this can be any command
the main issue is that bottom line you have 3 arrays with the same users(sorted by name ,looks exactly the same order)
but the foreach loops take user1 user2 user3 info instead of
user1(from array1)
user1(from array2)
user3(from array3)
and compares their data
array1[0] array2[0] array3[0] are the same user data(data itself is diffrent since i took diffrent snapshots of the data)
that is my main problem:(

August 9, 2017 at 6:59 am

take look at hashtables

pseudocode example:

#initialize hashes
$hash1 = $hash2 = $hash3 = @{}
#fill table with data (you code here)
foreach ($user in $users) {
$data1 = ...
$data2 = ...
$data3 = ...
$hash1[$user]=$data1
$hash2[$user]=$data2
$hash3[$user]=$data3
}
#compare
foreach ($kv in $hash1.GetEnumerator()) # enumerate users in first hash (or may be there should be "($user in $users)" ?
{
#get right values from hashes
$data1 = $kv.Value # or =$hash1[$user]
$data2 = $hash2[$kv.Key] # or =$hash2[$user]
$data3 = $hash3[$kv.Key] # or =$hash3[$user]
#compare data1,data2,data3 here
...
}