Programming:Windows PowerShell

From Wiki
Revision as of 10:41, 15 April 2016 by Deoren (talk | contribs) (Added example of omitting column headers in the output)
Jump to: navigation, search

Look up Active Directory group members

I found this tip on

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
Domain Users
Domain Computers
Workstation Admins
Company Users
Company Developers

Leave out column headers in output

Here is an example of querying the Services list, limiting the results to 10 items and then sorting them, all as raw values:

Get-Service | Select-Object -First 10 -ExpandProperty DisplayName | sort

This gives a bare list like so:

ActiveX Installer (AxInstSV)
Adobe Acrobat Update Service
Application Experience
Application Identity
Application Information
Application Layer Gateway Service
Application Management
ASP.NET State Service
Windows Audio
Windows Audio Endpoint Builder