Solved

in powershell how to parse the get-aduser output in order to filter the result with select-string ?

Posted on 2016-09-06
4
53 Views
Last Modified: 2016-09-07
Hello,

i'd like to recover some informations out of the get-aduser output.

todo so i thought i could pipe the output and then apply the "select-string" cmd as follows :

Get-ADUser -identity theIdentifiedUser -server myserver.ext.com  -Properties * | Select-String -Pattern '*last*'

Question:

how can i recover all lines - of the output - that have "last" in it ?

thank you in advance.

toshi
0
Comment
Question by:toshi_
  • 2
4 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 41786342
Get-ADUser output is not a string so you cannot use  Select-String to filter it..

You can filter based on property values.. You can modify the filter based on which property you want to filter.

Example to filter Displayname, use..
Get-ADUser -identity theIdentifiedUser -server myserver.ext.com  -Properties * | ?{$_.Displayname -match "Last"}

Open in new window

0
 
LVL 83

Accepted Solution

by:
oBdA earned 300 total points
ID: 41786344
Depends. What is it exactly you're looking for? Just all properties?
Then it's just a simple Select-Object:
Get-ADUser -identity theIdentifiedUser -server myserver.ext.com  -Properties * | Select-Object -Property '*last*'

Open in new window

If you really insist on a string-based search:
(Get-ADUser -identity theIdentifiedUser -server myserver.ext.com -properties * | Format-List | Out-String -Width 1024) -split "`r`n" | Select-String -Pattern "last"

Open in new window

0
 
LVL 40

Assisted Solution

by:Subsun
Subsun earned 200 total points
ID: 41786380
Another option, incase you want to phrase property values of the object..
Get-ADUser -identity theIdentifiedUser -server myserver.ext.com  -Properties * | %{$_.psobject.properties} | ?{$_.Value -match "Last"}| FL Name,Value

Open in new window

0
 

Author Comment

by:toshi_
ID: 41787384
Hello !

@Subsun : am i missing something with your first proposal as i dont have the display of the "DisplayName" ?  the second "to phrase property" is OK.

@oBda : your second proposal (i really insisted on a string -based search ;) ) is exactly was i was looking.


thank you so much
toshi
0

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 article shows how a content item can be identified directly or through translation of a navigation type. It then shows how this information can be used to create a menu for further navigation.
Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

15 Experts available now in Live!

Get 1:1 Help Now