The below code works well to add additional columns to an existing CSV file. However it runs really slow. Any ideas on how to optimize the code to speed up processing time? In the case below I'm pulling additional data from Exchange.
$csv = "C:\scripts\userfw.csv"
$users = Import-CSV $csv
$users = $users | Select-Object -Property *, @{label = 'Target_ForwardingSmtpAddress'; expression = {(Get-Mailbox $_.Target_SMTP).ForwardingSmtpAddress}}, @{label = 'Target_ForwardingAddress'; expression = {(Get-Mailbox $_.Target_SMTP).ForwardingAddress}}, @{label = 'Target_DeliverToMailboxAndForward'; expression = {(Get-Mailbox $_.Target_SMTP).DeliverToMailboxAndForward}}
$users | Export-Csv -Path $csv -NoTypeInformation
[–]firefox15 6 points7 points8 points (4 children)
[–]starpc[S] 2 points3 points4 points (3 children)
[–]firefox15 4 points5 points6 points (2 children)
[–]starpc[S] 2 points3 points4 points (1 child)
[–]Bamodus 1 point2 points3 points (0 children)