header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Reporting Account Types
Last Post 16 Nov 2008 02:59 AM by Shay Levy. 10 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
SynJunkieUser is Offline
Basic Member
Basic Member
Posts:126
Avatar

--
11 Nov 2008 02:50 AM

    Hello

    I have created a script and I wondered if anyone could suggest any improvements (not hard i'm sure).

    Basically, all my AD accouts have either the type of accounts they are (System, Departmental etc...) or the users job title in the Title field. My script goes through AD and basicaly counts up how many there are of each account and then displays this to the screen.

    The problem I am finding is that this takes up a massive amount of memory and my pc is not usable whilst PowerShell runs the script.

    Any suggestion on how to improve this woud be most welcomed.

    # Script to check for various types of accounts

    $Departmental = get-qaduser -title Departmental -sizelimit 0
    $Training = Get-QADUser -title Training -sizelimit 0
    $System = Get-QADUser -title System -sizelimit 0
    $Service = Get-QADUser -title Service -sizelimit 0
    $Users = Get-QADUser -sizelimit 0 | where { $_.title -ne "Training" -AND "Departmental" -And "Service"}
    $Total = Get-QADUser -Sizelimit 0

    write-host "There are a total of" $Total.count "Accounts"
    write-host "There are a total of" $Users.count "User Accounts"
    write-host "There are a total of" $System.count "System Accounts"
    write-host "There are a total of" $Departmental.count "Departmental Accounts"
    write-host "There are a total of" $Service.count "Service Accounts"
    write-host "There are a total of" $Training.count "Training Accounts"

     

    Thanks

    Lee 

     

    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    11 Nov 2008 02:59 AM
    Try this:

    Get-QADUser -sizeLimit 0 | group title -noElement


    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    SynJunkieUser is Offline
    Basic Member
    Basic Member
    Posts:126
    Avatar

    --
    11 Nov 2008 04:11 AM
    Thanks Shay. that is quicker but it doesn't perform the function that I created the script to perform, which is count up system, service, departmental and training accounts. Anything else is a user which I also need a total of.

    Any other ideas?

    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    11 Nov 2008 04:48 AM

    Since I can't work on your AD ;-), here's an example using the file system:


    PS > $acct = dir | group extension -NoElement
    PS > $acct

    Count Name
    ----- ----
    74
    138 .ps1
    6 .vbs
    1 .bat
    3 .xml
    8 .csv
    2 .rar
    2 .htm
    1 .InstallLog
    1 .JPG
    1 .fdf
    1 .wav
    6 .txt
    2 .cmd
    1 .html
    1 .config


    Get total count:

    PS > $total = $acct | measure-object -property count -sum
    PS > $total.sum
    248

    This is the equivalent of:
    # $Users = Get-QADUser -sizelimit 0 | where { $_.title -ne "Training" -AND "Departmental" -And "Service"}

    #$acct | where { $_.name -ne ".txt" -and $_.name -ne ".cmd" -and $_.name -ne ".ps1" }
    $acct | where { $_.name -notmatch "\.(txt|cmd|ps1)" }

    Count Name
    ----- ----
       74
        6 .vbs
        1 .bat
        3 .xml
        8 .csv
        2 .rar
        2 .htm
        1 .InstallLog
        1 .JPG
        1 .fdf
        1 .wav
        1 .html
        1 .config

    Makes sense?
     


    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    SynJunkieUser is Offline
    Basic Member
    Basic Member
    Posts:126
    Avatar

    --
    11 Nov 2008 07:24 AM
    Getting there. I now have this which is working great:

    $OU = "domain.co.uk/ou"
    get-qaduser -searchroot $OU -sizelimit 0 | where { $_.title -match "(service|training|system|departmental|Leaver)"} | group title | select Count,Name | ft -autosize

    But i still need a way to give me a count of what is left over (i.e standard users). Do you know if that is possible?
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    11 Nov 2008 07:49 AM

    Maybe this way. I would remove the select-object, adding -noElement to group-object leaves you with just the columns you're after. Notice the first foreach-object clause (begin), it defines a variable to hold the standard users count.


    get-qaduser -searchroot $OU -sizelimit 0 | foreach {$leftOver=0} {
       if( $_.title -match "(service|training|system|departmental|Leaver)") {
          $_
       } else { 
          $leftOver++
       }
    } | group title -noElement | ft -autosize

    $leftOver



     


    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    SynJunkieUser is Offline
    Basic Member
    Basic Member
    Posts:126
    Avatar

    --
    11 Nov 2008 08:46 AM

    I'll try that.  What I came up with in the meantime which sort of works is:

     

    $user = get-qaduser -sizelimit 0 | where { $_.title -notmatch "(Service|Training|System|Departmental|Leaver)"}; write-host "User Accounts:" $user.count; get-qaduser -sizelimit 0 | where { $_.title -match "(Service|Training|System|Departmental|Leaver)"} | group title | select Count,Name | ft -autosize

    This works alot faster than what my origional script did but.......... if the user account has a title such as "Departmental Trainer"  it gets counted seperately.  I think its because of the -match operator but after trying the others such as -eq and -like nothing works. If i can get that ironed out then I'm basically there.

     

     

    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    13 Nov 2008 01:20 AM
    You want "Departmental Trainer" to be counted as Departmental ?

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    SynJunkieUser is Offline
    Basic Member
    Basic Member
    Posts:126
    Avatar

    --
    14 Nov 2008 03:04 AM
    No, because that is a Job Title rather than an account type. I'm using the Title field on Service accounts, Training accounts, Departmental Accounts (shared mailboxes) etc....

    like I said, All i ideally would like to do is count how many departmental Accounts, Training accounts, System Accounts and Service Accounts I have. Anything else I class as a standard user which I also want to total up.

    what is strange is that the -match operator allows me to use the | as an OR:

    $OU = "doman.co.uk/ou"; get-qaduser -searchroot $OU -sizelimit 0 | where { $_.title -match "(service|training|system|departmental|Leaver)" }

    but the -eq doesn't


    $OU = "doman.co.uk/ou"; get-qaduser -searchroot $OU -sizelimit 0 | where { $_.title -eq "(service|training|system|departmental|Leaver)" }


    if it did this would be alot easier I think.
    aleksandarUser is Offline
    New Member
    New Member
    Posts:54
    Avatar

    --
    15 Nov 2008 12:32 PM
    > what is strange is that the -match operator allows me to use the | as an OR:

    The -match operator does regular expression comparison (case insensitive). Alternation is the regular expression equivalent of "or" and a vertical bar or pipe symbol is an alternation operator.

    -aleksandar
    http://powershellers.blogspot.com
    Follow me on Twitter: http://twitter.com/alexandair
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    16 Nov 2008 02:59 AM

    I would go this way:

    # query all user objects ONCE only
    $users = get-qaduser -searchroot $OU -sizelimit 0

    # Group them by title on an *offline* object
    $titles = $users | group title -noElement

    Now filter the ones you want either by matching titles or whatever.


    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer