none
how to avoid overwriting the output with select -ExpandProperty RRS feed

  • Question

  • When i try with below command the output is getting overwrriten. Please let me know how to avoid it.

    The input file contains multiple colum with employeeid coloum and i'm trying to pull user based on employeeid, i'm able to see complete report on powershell but Only the problme with exporting.

    $a = Import-Csv C:\gp.csv | select -ExpandProperty employeeid
    foreach ($b in $a)
    {Get-ADUser -filter { employeeid -eq $b } -Properties * | select DisplayName, samaccountname, employeeid |Export-Csv -Path C:\sl.csv -NoTypeInformation}

    Friday, October 18, 2019 4:32 PM

Answers

  • It would be worth you time to spend some learning the very basic steps of PowerShell scripting.

    Import-Csv C:\gp.csv |
    	ForEach-Object{
    		Get-ADUser -filter "employeeid -eq '$($_.employeeid)'" -Properties * 
    	}|
    	select DisplayName, samaccountname, employeeid |
    	Export-Csv -Path C:\sl.csv -NoTypeInformation


    \_(ツ)_/

    • Marked as answer by Partha1012 Friday, October 18, 2019 5:30 PM
    Friday, October 18, 2019 5:24 PM
    Moderator

All replies

  • It would be worth you time to spend some learning the very basic steps of PowerShell scripting.

    Import-Csv C:\gp.csv |
    	ForEach-Object{
    		Get-ADUser -filter "employeeid -eq '$($_.employeeid)'" -Properties * 
    	}|
    	select DisplayName, samaccountname, employeeid |
    	Export-Csv -Path C:\sl.csv -NoTypeInformation


    \_(ツ)_/

    • Marked as answer by Partha1012 Friday, October 18, 2019 5:30 PM
    Friday, October 18, 2019 5:24 PM
    Moderator
  • Expected reply! Thank you.
    Friday, October 18, 2019 5:30 PM
  • You can do:

    export-csv -append

    • Edited by JS2010 Friday, October 18, 2019 5:34 PM
    Friday, October 18, 2019 5:34 PM