Creating tables

Hi,

I want to do following.

Check in whole Domain users who use fax “033033…” and users who use “033000” and see result in table with:

Fax number | count of users

033033… | 10
033000… | 5

Is it possible with powershell? Or will i need to filter each number seperately?

Get-ADUser -properties Fax |where fax -like $fax | select name | measure | select-object Count | export-csv c:\temp\FAX.csv -Delimiter “;” -encoding “unicode” -NoTypeInformation

This only gives me result for one fax number (obviously) and table with Count (obviously :))

Run Get-ADuser with filter criteria to only get those fax numbers. Pope the results to Group-Object. Make sure you specify to retrieve the fax property and group on that.

You might just need to add -append to your cmdlet

But there is always many ways to do what you want to do in powershell. Best Rule is to Filter before the Pipe with ADUser as this will save a lot of time depending on enviroment size.

$Fax_033033 = Get-ADUser -Filter {facsimileTelephoneNumber -like '033033'}  -Properties facsimileTelephoneNumber | Select-Object Name,facsimileTelephoneNumber | Export-csv -notypeinformaiton c:\temp\Fax_033033.csv
$Fax_033000 = Get-ADUser -Filter {facsimileTelephoneNumber -like '033000'}  -Properties facsimileTelephoneNumber | Select-Object Name,facsimileTelephoneNumber | Export-csv -notypeinformaiton c:\temp\Fax_033000.csv

Here's another little tip always check to see what Covertto-CSV will show up. 

PS C:\WINDOWS\system32> Get-ADUser -Filter {facsimileTelephoneNumber -like '033033'} -Properties facsimileTelephoneNumber | Select-Object Name,facsimileTelephoneNumber | ConvertTo-Csv 
#TYPE Selected.Microsoft.ActiveDirectory.Management.ADUser
"Name","facsimileTelephoneNumber"
"Lastname, FirstName","(123) 456-7890"



The Attribute for Fax shows in Aduc as FacsimileTelephone Number

But is it possible to get final result in this way:

In one CSV file generated from Powershell:

Fax number | count of users

033033… | 10
033000… | 5

and so on.

I have problem how to filter more then number. I can do it with one number - but how to do it with multiple ones this is where im stuck

OK - i made some progress :wink:

What im left do know:

$033033
$033000

This Variables now have counts for each number.

How to export both of them into one CSV?

So in csv it will havee at least two columns:

number | count

:slight_smile:

$Fax1 = Get-ADUser -Filter {fax -like ‘901’} -Properties fax | Select-Object Name,fax
$Fax2 = Get-ADUser -Filter {fax -like ‘001’} -Properties fax | Select-Object Name,fax

$Fax1.count
$Fax2.count

$object = New-Object –TypeName PSObject
$object | Add-Member –MemberType NoteProperty –Name “901” –Value $Fax1.count
$object | Add-Member –MemberType NoteProperty –Name “001” –Value $Fax2.count
Write-Output $object

Almost there :slight_smile: just need to get two seperate columns in csv now :slight_smile:

Try this approach. You want to loop through the number, query AD and then you can use calculated expressions to get the count for every number. Each result is stored in your results variable and then you can export it to a CSV if you so desire. Double check the LIKE statement, there were no wildcard characters, so I added them.

$numbers = '901', '001'

$results = foreach ($number in $numbers) {
    $faxes = Get-ADUser -Filter {fax -like "*$number*"} -Properties fax 
    $faxes | Select Name,
                    Fax,
                    @{Name="Count";Expression={$faxes.Count}}
}

$results | Export-CSV C:\Scripts\faxes.csv -NoTypeInformation