Question about Calculated Properties - hash tables

Hello again,

I have this:

$CALC = “Name”,
@{Name=“Phone”;Expression={$.telephoneNumber}},
@{Name=“Office”;Expression={$
.office}},
@{Name=“Homepage”;Expression={$.homepage}},
@{Name=“Country”;Expression={$
.co}},
@{Name=“Company”;Expression={$.company}},
@{Name=“Fax”;Expression={$
.Fax}},
@{Name=“Script”;Expression={$.scriptpath}}
#now count
$COUNT = @{Name=“Phone”;Expression={$
.telephoneNumber.count}}

The first one works exactly as i want.

But i need second with will give me only counts for phones.

But the result i get is:

Phone
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

And so on till 152…
I want to look like that at least

Phone
152
152
152
152
152
152
152
152

With is not really ideal - but -unique fix the problem and results look good in CSV.

I can get this second output if put in full name of $:

$COUNT = @{Name=“Phone”;Expression={$userspoland.telephoneNumber.count}}

Why this happens?

I can do it this way - but it will become bloated as i have many countries filtered…

Well, $_ is ‘this record’ or the current record. You are getting the count of the phonenumber in the telephone attribute of the user. You don’t have to filter each country, try using Group-Object:

$users | Where {$_.telephone} | Group-Object -Property Country -NoElement | Sort-Object Count -Descending

You could append them to your $Users with something like:

$grouped = $users | Where {$_.telephone} | Group-Object -Property Country -NoElement | Sort-Object Count -Descending
foreach ($group in $grouped) {
    $users | Add-Member -MemberType NoteProperty -Name ("TotalPhone{0}" -f $group.Name) -Value $group.Count
}

The only result it gives me:

Add-Member : Cannot add a member with the name “TotalPhone” because a member with that name already exists. To overwrite the member anyway, add the Force parameter to
your command.

Other thing - is it possible to get phone number itself - and then how many times it is used?

I done this way:

$offices = {}
$offices | select @{n=“Phone”; e={($userspol | ? telephonenumber -eq “5698”).count}},
@{n=“Office”; e={($userspol | ? office -eq “Warsaw”).count}},
@{n=“Homepage”; e={($userspol | ? homepage -eq “google.pl”).count}},
@{n=“Country”; e={($userspol | ? Co -eq “Poland”).count}},
@{n=“Company”; e={($userspol | ? Company -eq “google”).count}},
@{n=“Fax”; e={($userspol | ? Fax -EQ ‘+901’).count}},
@{n=“Script”; e={($userspo | ? scriptpath -EQ ‘warsaw\warsaw.bat’).count}} | export-csv $LocationFileWarsaw\WarsawCOUNTS.CSV -NoTypeInformation

I guess it can be done differently - but at least this way does what it should :wink: