How do I pass PSCustomObject objects from an Import-CSV to the Get-ADUser cmdlet?

Hello,

I execute the following and get the error that follows.  The $IDs vaiable is a PSCustomObject object, but Get-Aduser wants a type of ADUser object.  So how can a pass a CSV file of PSCustomObjects to a Get-ADuser cmdlet?

$IDs = import-csv testids.csv
foreach ($Account in $IDs) {
$IDAttrs = get-aduser $Account -properties *
The CSV file has SamAccount Names as follows:
ID
__
AU
DU
Joe

Get-ADUser : Cannot bind parameter 'Identity'. Cannot convert the "@{ID=AU}" value of type "System.Management.Automation.PSCustomObject" to type "Microso
ft.ActiveDirectory.Management.ADUser".		
October 3rd, 2013 10:34pm

Try like this way :

IDs = import-csv testids.csv

foreach ($Account in $IDs) {

$IDAttrs = get-aduser $Account.ID -properties *

}

Free Windows Admin Tool Kit Click here and download it now
October 3rd, 2013 11:06pm

Thanks Tarique....that works, but why?

The $Account.ID is a System.String object type, but the Get-Aduser wants a ADUser object type?  Im confused.

October 3rd, 2013 11:16pm

becouse in your csv   you have  ID header   and you are passing the value from CSV .

see help on Get-aduser :

    

PS C:\Temp> Get-Help Get-ADUser -Parameter identity

-Identity <ADUser>
    Specifies an Active Directory user object by providing one of the following property values. The identifier in parentheses is the LDAP display name for the  attribute.

      Distinguished Name 
        Example:  CN=SaraDavis,CN=Europe,CN=Users,DC=corp,DC=contoso,DC=com
      GUID (objectGUID) 
        Example: 599c3d2e-f72d-4d20-8a88-030d99495f20 
      Security Identifier (objectSid) 
        Example: S-1-5-21-3165297888-301567370-576410423-1103
      SAM account name  (sAMAccountName) 

        Example: saradavis

Free Windows Admin Tool Kit Click here and download it now
October 3rd, 2013 11:19pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics