This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Quest ActiveRoles script logic

Hello, first time poster, but this is really confusing me.

I have a very basic script but my logic is wrong because I’m not getting the results I need.

 

Background info, I have a csv containing a list of email addresses like a@aol.com, b@aol.com, c@aol.com

Here’s the script

 

Add-PSSnapin Quest.ActiveRoles.ADManagement

Get-Content C:\WhateverTempFile.csv |

Foreach{

Get-QADUser -SizeLimit 9999 -proxyaddress "*$_*" |

Select-Object $_, SamAccountName, givenName, Lastname}|  Export-Csv C:\Results.csv

 

The results look like this

 

"a@aol.com","SamAccountName","givenName","LastName"

,"a","Andy","Fake"

,"b","Brandy","Fake"

,"c","Candy","Fake"

 

The problem is, I want the email address for each user, but it seems to be querying ADUC for an attribute called a@aol.com (which isn’t finding anything… so the results are null for all users)

How do I get that original value to display for each user?

  • Select-object will select an attribute from the piped object.

    In this context, your piped object is the result of an iteration of the get-qaduser cmdlet, which is is a User object. There isn't an attribute on the User object which has the name of the email address of the User, so I'd expect the output that you are seeing.

    In PowerShell, selecting isn't the same as formatting.

    Each object that you select actually has two attributes: the name of the object, and the value of the object. When want to want to use a constructed attribute, like this, you have to provide both values.

    Use something like this:

    $emails = Get-Content C:\list.csv

    Foreach ($email in $emails){Get-QADUser -SizeLimit 9999 -proxyaddress "*$email*" |`
    Select-Object @{N='Email';E={$email.ToString()}}, samaccountname, givenName, SN}

    The 'N' stands for Name, and the 'E' stands for Expression.

    Hope that helps!
  • Thank you so much Terrance, that worked perfectly!