output total number of users in AD groups.

Posted on 2014-08-22
Last Modified: 2014-08-23

I am trying to get the total number of group members to output to a file and cant figure it out .
I just need a simple file .. txt or .csv that will show the total group members of groups that are in groups.txt

Below works but I want the output to a file .
If ([array]$users = (gc groups.txt | Get-ADGroupMember))
      "Number of users in groups: $($users.count)"

I tried below but I cant get it to just output a one liner with the total count.

$Users | Select * | Export-Csv Groupcount_$((Get-Date -Format MM-dd-yyyy)).csv -NoTypeInformation
Question by:MilesLogan
    LVL 18

    Accepted Solution

    If ([array]$users = (gc groups.txt | Get-ADGroupMember))
          "Number of users in groups: $($users.count)" | out-file c:\temp\UserCount.txt
    LVL 2

    Author Closing Comment

    Thank you Raheman

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
    I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
    This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
    This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now