Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
298 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 85

Accepted Solution

by:
oBdA earned 1200 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 800 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
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…
Screencast - Getting to Know the Pipeline

782 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