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]
0 comments