Welcome to MSDN Blogs Sign in | Join | Help

Get-Everyone

Jeffery Snover just posted a Get-Me script.  The Get-Me script finds out the principal of the user running PowerShell.  In case you ever wanted to know how to get all of the users on a machine (or from a domain), here's a quick function that queries WMI for users.

function Get-Everyone([switch]$fromDomain) {
    #.Synopsis
    #   Gets all users
    #.Description
    #   Queries WMI to get all users.  To save time, queries
    #   are local unless the -fromDomain switch is used
    #.Parameter fromDomain
    #   If set, gets domain users as well as local accounts
    #.Example
    #   # Get All Local Accounts
    #   Get-Everyone
    #.Example
    #   # Get All Local & Domain Accounts
    #   Get-Everyone -fromDomain
    $query = "Win32_UserAccount"
    if (-not $fromDomain) {
        $query+= " WHERE LocalAccount='True'"
    }
    Get-WmiObject $query
}

All of the comments are an example of comment-based help, which is feature of PowerShell that is available in CTP3 and Window 7 Betas (when they are out).

This means that I can embed examples within a function, as I did above.

# Get All Local Accounts
Get-Everyone

# Get All Local & Domain Accounts
Get-Everyone -fromDomain

Hope this helps,

James Brundage [MSFT]

Published Tuesday, December 02, 2008 9:04 PM by PowerShellTeam
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Dew Drop - December 3, 2008 | Alvin Ashcraft's Morning Dew

Wednesday, December 03, 2008 9:39 AM by Dew Drop - December 3, 2008 | Alvin Ashcraft's Morning Dew

# re: Get-Everyone

Can you elucidate on the comment based help? Sounds very interesting, but the script above just looks like a well documented script, and nothing special. What am I missing?

Thursday, December 04, 2008 7:08 PM by tfl

# re: Get-Everyone

@tfl, if you just wait a little bit, CTP3 will be released and we'll all have access to the help files and binaries and will be able to play with this new feature.

Tuesday, December 09, 2008 10:10 PM by Hal Rottenberg

# PowerShell: One Year Later

At the end of 2007, I made a New Year's resolution to start using PowerShell as my command window. Amazingly,

Wednesday, December 31, 2008 7:56 PM by John Robbins' Blog

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker