How to add list of names to add exiting CSV file on next row

49 views Asked by At

Here I want the $newdata data in the next row on the same CSV file, but the result is like below:

NewManager
---------- 
Sathiya Priya Naveen Kumar
Sathiya Priya Naveen Kumar
Sathiya Priya Naveen Kumar
Sathiya Priya Naveen Kumar
Sathiya Priya Naveen Kumar
Sathiya Priya Naveen Kumar
Sathiya Priya Naveen Kumar
Sathiya Priya Naveen Kumar

But actually the data is:

NewManager
---------- 
Karthikeyan Deenadhayalan
Karthikeyan Deenadhayalan
Sathiya Priya Naveen Kumar
Karthikeyan Deenadhayalan
Karthikeyan Deenadhayalan
Sathiya Priya Naveen Kumar
Karthikeyan Deenadhayalan
Sathiya Priya Naveen Kumar

My code:

cls
$NewData = $Olddata |
           Select @{n="NewManager";e={(Get-ADUser $_.Manager -Properties *).DisplayName}} |
           %{$_.NewManager} |
           Out-File C:\Users\Administrator.ROOTDC1\Desktop\test1.txt -Force
$import = Import-Csv $path
$print = gc C:\Users\Administrator.ROOTDC1\Desktop\test1.txt
foreach ($prints in $print) {
    #I want to add new manager list on the same file in the next row.
    foreach ($imp in $import) {
        Add-Member -InputObject $imp -MemberType NoteProperty -Name NewManager -Value $prints -Force
    }
}
$import
0

There are 0 answers