locked
Getting the number of users on each dial plan RRS feed

  • Question

  • We have about 50 or so dial plans, and I'd like to get a report of how many users are assigned to each dial plan.

    Here are the results of one powershell cmd:

    PS C:\work> (get-csuser -filter {dialplan -eq "lync-dp1"}).count
    164

    Fantastic, I get 164 back which is how many users are in that dialplan called Lync-DP1.

    Now, I've made an array:

    PS C:\work> $dialplans = @("lync-dp1", "lync-dp2")
    PS C:\work> $dialplans
    lync-dp1
    lync-dp2

    Fantastic, now I have an array that I can feed into the previous command that seemed to work great.  But the following fails; it just sits there with no output.  I have to Ctrl-C to get out of this:

    PS C:\work> (get-csuser -filter {dialplan -eq $dialplans}).count

    I've even tried to put quotes around each object in the array variable, like this:

    PS C:\work> $dialplans = @('"lync-dp1"', '"lync-dp2"')
    PS C:\work> $dialplans
    "lync-dp1"
    "lync-dp2"

    And I still get the same results.

    Can anyone help me with putting a variable array into this .count command?  Or is there a better/easier way to get the numbers of users with a specific dial plan assigned?


    • Edited by Lync Viking Thursday, September 12, 2013 6:40 PM adding code blocks
    Thursday, September 12, 2013 6:38 PM

Answers

  • Hi, 

    Try this - please note this will work only if you have dial plans with user's scope. Dial plan with site and pool scope will return a error.

    $dialsP = get-csdialplan 
    foreach ($dialplanz in $dialsP)
    {
    $dp = $dialplanz.identity
    $totalusers = (get-csuser -filter {dialplan -eq $dp}).count
    Write-Host $dialplanz.identity ":" $totalusers
    }

    Rgs, H

    _______________________________________________________________________________________________________________________________
    If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer"

    • Marked as answer by Kent-Huang Wednesday, September 18, 2013 1:21 PM
    Thursday, September 12, 2013 9:06 PM
  • Hi,

    Here is a great blog counting number of users assigned to your per-user policies.

    http://blogs.technet.com/b/nexthop/archive/2010/06/06/scriptnumberofusersassignedtopolicies.aspx?Redirected=true

    Please note If the user haven’t been assigned a per-user policy that means the user is either under the sway of a policy configured for user’s pool or site.


    Kent Huang
    TechNet Community Support

    • Marked as answer by Kent-Huang Wednesday, September 18, 2013 1:21 PM
    Friday, September 13, 2013 2:27 AM

All replies

  • Hi, 

    Try this - please note this will work only if you have dial plans with user's scope. Dial plan with site and pool scope will return a error.

    $dialsP = get-csdialplan 
    foreach ($dialplanz in $dialsP)
    {
    $dp = $dialplanz.identity
    $totalusers = (get-csuser -filter {dialplan -eq $dp}).count
    Write-Host $dialplanz.identity ":" $totalusers
    }

    Rgs, H

    _______________________________________________________________________________________________________________________________
    If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer"

    • Marked as answer by Kent-Huang Wednesday, September 18, 2013 1:21 PM
    Thursday, September 12, 2013 9:06 PM
  • Hi,

    Here is a great blog counting number of users assigned to your per-user policies.

    http://blogs.technet.com/b/nexthop/archive/2010/06/06/scriptnumberofusersassignedtopolicies.aspx?Redirected=true

    Please note If the user haven’t been assigned a per-user policy that means the user is either under the sway of a policy configured for user’s pool or site.


    Kent Huang
    TechNet Community Support

    • Marked as answer by Kent-Huang Wednesday, September 18, 2013 1:21 PM
    Friday, September 13, 2013 2:27 AM
  • When I ran that just as it was, it returned the total number of users in my system, for each dial plan.

    It was formatted wonderfully, but it looked something like this.  Imagine I have 10000 users

    dp1 : 10000

    dp2 : 10000

    etc.

    Not sure where it went wrong but thanks for the advice, I think I'm getting closer.

    Also, I checked this blog from another post by Kent Huang in this thread: 

    http://blogs.technet.com/b/nexthop/archive/2010/06/06/scriptnumberofusersassignedtopolicies.aspx?Redirected=true

    So then I tried the following:

    $identities = @()

     $policies = Get-csdialplan -Filter "tag:*" | Select-Object Identity

     foreach ($i in $policies)

        {

            $x = $i.Identity

            $x = $x -replace "Tag:",""

            $identities += $x

        }

     foreach ($policy in $identities)

        {

            $policy

            (Get-CsUser -Filter {dialplan -eq $policy}).Count

        }

    And it returned the exact same thing as above: it gave me the total number of users that have dial plans, for each dial plan.

    This works so great:

    (get-csuser -filter {dialplan -eq "lync-dp1"}).count

    Is there a way I can just replace the "lync-dp1" up there with an array variable that has all my dialplans in it?

    Thanks for the help everyone.


    Friday, September 20, 2013 4:02 PM
  • This one worked for me...

    $Dialplans = Get-CSDialPlan -Filter "tag:*"

    ForEach ($Dialplan in $DialPlans)
    {
    $DPName = $Dialplan.SimpleName
    $DPName
    (Get-CSUser -Filter {Dialplan -eq $DPName}).Count
    }


    Ken Lasko | Lync MVP | http://UCKen.blogspot.com | http://LyncOptimizer.com

    Friday, September 20, 2013 5:53 PM
  • Thanks Ken, but that did not work for me for some reason.

    It still returns the total number of users; for each dial plan.

    Can someone explain why this works:

    (get-csuser -filter {dialplan -eq "lync-dp1"}).count

    and returns 138 (which is correct)

    But this does not?:

    $dptest = "lync-dp1"

    (get-csuser -filter {dialplan -eq $dptest}).count

    It returns roughly 127000 (which is our total number of users)

    Tuesday, September 24, 2013 7:39 PM
  • Got this from the Powershell forum; it was the only thing that worked for me:

    $dialtests="lync-dp1","lync-dp2","lync-dp3"
    foreach ($dialtest in $dialtests){
      $sb=[scriptblock]::Create("dialplan -eq $dialtest")
      (get-csuser -filter $sb).count
    }

    From what I understand, my variable was out of scope for the command. 

    Thanks everyone!

    Thursday, September 26, 2013 2:47 PM