I would like to export several multi-value "fields" from Microsoft Active Directory. Instead of defining all "array pointers" manually I want to generate them automatically.
I already checked Powershell outputting array items when interpolating within double quotes and tried out several alterantives but I always get stuck with the expressions
$SearchBases ='dummy.com','dummy2.com'
$csv_file_path = "C:\Test\Export.csv"
$properties_select = ''
$properties_multivalue = 'proxyAddresses','showInAddressBook','memberOf'
# go through each multi_value property and automatically generate 8 fields for upto 8 array elements
ForEach($prop in $properties_multivalue) {
for ($i=0; $i -le 8; $i++) {
$properties_select += @{Name=$prop+'_'+$i; Expression={$_.$($prop[$i])}}
}
}
ForEach($SearchBase in $SearchBases) {
Get-ADObject -filter 'objectClass -eq "contact"' -SearchBase $SearchBase -properties $properties_multivalue
|SELECT-Object $properties_select
|Export-Csv -Append -Force -Delimiter ";" -NoClobber -Encoding UTF8 -path $csv_file_path
}
I suspect that i do something wrong at
$properties_select += @{Name=$prop+'_'+$i; Expression={$_.$($prop[$i])}}
Any help/hints are useful.
Thanks Chris