Microsoft.ActiveDirectory.Management.ADPropertyValueCollection

Hi all, i have another problem.

$listaaccounts = import-csv “E:\appoggio\Scripts\Export attributo\Listaaccountstest.txt”
foreach($account in $listaaccounts)
{ Get-ADUser -identity $account.accounts -properties otherMobile,name | select otherMobile,name }

Produce this output:

otherMobile name


{+393474174923} Atzei, Antonello (Portovesme - IT)
{+393485735339} Annalisa Atzeni
And this is ok.
But if i try to export the output in a .txt file :

$listaaccounts = import-csv “E:\appoggio\Scripts\Export attributo\Listaaccountstest.txt”
foreach($account in $listaaccounts)
{Get-ADUser -identity $account.accounts -properties otherMobile,name | select otherMobile,name | select otherMobile,name | export-csv “E:\appoggio\Scripts\Export attributo\Exportcels.txt” -append

The output on the .txt file is this:
"otherMobile","name"
"Microsoft.ActiveDirectory.Management.ADPropertyValueCollection","Atzei, Antonello (Portovesme - IT)"
"Microsoft.ActiveDirectory.Management.ADPropertyValueCollection","Annalisa Atzeni".

The question is: why i get "Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" in the output file ?

thankyou.

The content of the attribute is obviously a collection - not a single value. You have to turn it into a string before you can export it. Something like this should work:

$listaaccounts = Import-Csv -Path 'E:\appoggio\Scripts\Export attributo\Listaaccountstest.txt'
$Result =
foreach($account in $listaaccounts){
    Get-ADUser -Identity $account.accounts -Properties otherMobile,name | 
    Select-Object -Property name,@{Name = 'MobileNumbers'; Expression = {($_.otherMobile) -join ';' }}
    
}
$Result |
Export-Csv -Path 'E:\appoggio\Scripts\Export attributo\Exportcels.csv' -Delimiter ',' -NoTypeInformation
1 Like

Great !!!
Thankyou Olaf.