Forum Discussion
bulk update extension attribute in AD
To Export the Hash table you will need to use the GetEnumerator()
https://tommymaynard.com/hash-table-to-csv-2018/
I recommend that you replace the hash table with PSObject
I have made the below changes but each iteration of foreach loop saves to $Output. It overwriting what was there previously, i.e., the previous iteration. Which means that only the very last iteration is saved to $Output and exported.
- farismalaebSep 29, 2020Iron Contributor
Yes, sure as the $Output=@() is inside the loop and is being reset everytime, a very quick fix will be to add a new variable at the top
and once the $output have the result, add it to the variable
try the code below and get the result from $allresult variable.
$allresult=@() Import-Csv -path C:\123\EXDB1.csv |ForEach-Object { $Output = @() Set-ADComputer $_.samAccountName -replace @{ ExtensionAttribute4 = "$($_.ExtensionAttribute4)" ExtensionAttribute6 = "$($_.ExtensionAttribute6)"} $Output =New-Object -TypeName PSObject -Property @{ samAccountName = "$($_.samAccountName)" ExtensionAttribute4 = "$($_.ExtensionAttribute4)" ExtensionAttribute6 = "$($_.ExtensionAttribute6)" $allresult=$output } } $Output | Export-Csv C:\Temp\OwnerTest2.csv -NoTypeInformation -Encoding UTF8 -Append- SushantjhaSep 29, 2020Copper Contributor
Still last iteration is saved to $Output and exported, I am not getting all the results.
- farismalaebSep 30, 2020Iron Contributor
Did it work ?