Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Query AD Field Output From Get-ADUser - Convert DN to Email?

$
0
0

I've got an interesting problem and I cannot find any help via search engines.  Here's the skinny...I have a script that queries Active Directory and finds enabled users inside a specific OU that meet a certain criteria.  

Get-AdUser -SearchBase $SearchOU -properties userAccountControl, whenChanged | Where-Object {$_.whenChanged -le $DateFilter}

I want to take the output from this command...which will return a few user accounts...and I want to find the Manager which is listed on the organization tab in ADUC for each of those users.

The issue is...when I try to foreach loop through these results, it returns the Manager as a Distinguished name....so when I try to insert this into my email results, I get invalid operation errors for the recipient being invalid type...since it is a DN, it isn't an email address.

 

So my question is...how do I change this?  How do I take the output from a query, foreach loop through it (probably twice since I'll need to query the manager and then query/convert the manager's email) to send out the results to each person listed on the Manager field of each individual user?  

I've asked this in numerous places and no one has answers yet...hopefully someone does here!  Thanks in advance!


Viewing all articles
Browse latest Browse all 6937

Trending Articles