Hi,
The Add-Member cmdlet can add properties to an object for you.
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/add-member?view=powershell-7.1
It could be like this
Import-CSV D:\id.csv |
ForEach-Object {
$obj = Get-ADUser -Filter "name -eq $($_.id)" -Properties column1,column2,column3 |Select-Object column1,column2,column3
$_ |
Add-Member -MemberType NoteProperty -Name column1 -Value $obj.column1 -PassThru |
Add-Member -MemberType NoteProperty -Name column2 -Value $obj.column2 -PassThru |
Add-Member -MemberType NoteProperty -Name column3 -Value $obj.column3 -PassThru
} |
Export-CSV D:\result.csv -NoTypeInformation
Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.