Creating tables

Welcome Forums General PowerShell Q&A Creating tables

This topic contains 6 replies, has 4 voices, and was last updated by

2 years, 2 months ago.

  • Author
  • #59151

    Points: 0
    Rank: Member


    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 :))

  • #59152

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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.

  • #59155

    Points: 68
    Rank: Member

    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
    "Lastname, FirstName","(123) 456-7890"

    The Attribute for Fax shows in Aduc as FacsimileTelephone Number

  • #59226

    Points: 0
    Rank: Member

    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

  • #59229

    Points: 0
    Rank: Member

    OK – i made some progress 😉

    What im left do know:


    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


  • #59232

    Points: 0
    Rank: Member

    $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


    $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 🙂 just need to get two seperate columns in csv now 🙂

  • #59233

    Points: 527
    Helping Hand
    Rank: Major Contributor

    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,
    $results | Export-CSV C:\Scripts\faxes.csv -NoTypeInformation

The topic ‘Creating tables’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort