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
164 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_
[X]
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
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 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