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
70 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A brief introduction to what I consider to be the best editor for PowerShell.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

16 Experts available now in Live!

Get 1:1 Help Now