Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
125 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 84

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
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 …

828 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