Evaluate a string and use it in a command?

I have the following code:

$EAs = “ExtensionAttribute1″,”ExtensionAttribute2″,”ExtensionAttribute3″,”ExtensionAttribute4″,”ExtensionAttribute5″,”ExtensionAttribute6″,”ExtensionAttribute7″,”ExtensionAttribute8″,”ExtensionAttribute9″,”ExtensionAttribute10″,”ExtensionAttribute11″,”ExtensionAttribute12″,”ExtensionAttribute13″,”ExtensionAttribute14″,”ExtensionAttribute15”

foreach ($EA in $EAs)

{ foreach ($User in $Users) { if ($User.$EA -ne $null) { Write-host "$EA has value " + $User.EA$ } } } 

I’m trying to read 16 related attributes from AD for all users in the domain, to identify those user “extensionAttribute”[1-15] values in a concise script. This requires that the code evaluate $User.$EA as each value from the array sequentially. How can I do this?

submitted by /u/ilovetpb
[link] [comments]

Leave a Reply