Difference between revisions of "Programming:Windows PowerShell"

From WhyAskWhy.org Wiki
Jump to: navigation, search
m (Added alternate (non-PowerShell) command)
m (Added example of dumping list of groups that a user account is a member of (lifted directly from stack overflow))
Line 20: Line 20:
 
dsquery group -name "MyADGroupName" | dsget group -members -expand
 
dsquery group -name "MyADGroupName" | dsget group -members -expand
 
</code>
 
</code>
 +
 +
== Look up group memberships for user account ==
 +
 +
<syntaxhighlight lang="powershell">
 +
Import-Module ActiveDirectory
 +
Get-ADPrincipalGroupMembership username | select name
 +
</syntaxhighlight>
 +
 +
<pre>
 +
name
 +
----
 +
Domain Users
 +
Domain Computers
 +
Workstation Admins
 +
Company Users
 +
Company Developers
 +
AutomatedProcessingTeam
 +
</pre>
  
  
Line 26: Line 44:
 
* [[wikipedia:Windows_PowerShell|Wikipedia entry]]
 
* [[wikipedia:Windows_PowerShell|Wikipedia entry]]
 
* [http://serverfault.com/questions/49405 Command line to list users in a Windows Active Directory group?]
 
* [http://serverfault.com/questions/49405 Command line to list users in a Windows Active Directory group?]
 +
* [http://stackoverflow.com/questions/5072996/how-to-get-all-groups-that-a-user-is-a-member-of How to get all groups that a user is a member of?]

Revision as of 17:29, 2 February 2016



Look up Active Directory group members

I found this tip on ServerFault.com.

Import-Module ActiveDirectory
Get-ADGroupMember "MyADGroupName" | Select-Object name | Sort-Object name

Unfortunately that doesn't expand all group members, whereas this command-line tool does:

dsquery group -name "MyADGroupName" | dsget group -members -expand

Look up group memberships for user account

Import-Module ActiveDirectory
Get-ADPrincipalGroupMembership username | select name
name
----
Domain Users
Domain Computers
Workstation Admins
Company Users
Company Developers
AutomatedProcessingTeam


Links