如何添加名称列表以在下一行添加现有的CSV文件

时间:2019-01-14 14:44:45

标签: powershell

在这里,我想在同一CSV文件的下一行中$newdata数据,但结果如下:

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

但是实际上数据是:

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

我的代码:

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 个答案:

没有答案