Adding addition custom field to CSV using Powershell.

cbriss911 1 Reputation point
2021-06-11T10:02:56.573+00:00

104781-image.png

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2021-06-11T10:43:47.997+00:00

    Hi,

    Please use the Ctrl-K tool to post the code. To add properties you can use the Add-Member cmdlet.

    Import-Csv -Path $file | ForEach-Object{  
        $dn = $_.User  
        $ADEndDate = (Get-ADUser -Filter "DisplayName -like '*$dn*'" -Properties AccountExpirationDate).AccountExpirationDate  
        $_ | Add-Member -NotePropertyName "ADEndDate" -NotePropertyValue $ADEndDate -PassThru  
    } | Export-Csv -Path $outputfile  
    

    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.