简体   繁体   English

使用Powershell在每行的开头添加文本

[英]Add text to the beginning of each line using Powershell

I'm using Powershell to export users to a CSV. 我正在使用Powershell将用户导出到CSV。 Everything works fine but I would like to add commands for Live@edu to each line for import. 一切正常,但我想将Live @ edu的命令添加到每一行以进行导入。 The text I would like to add is "Add,Mailbox," before each line. 我要添加的文本是每行之前的“添加,邮箱”。 Can this be done before the export-csv? 可以在export-csv之前完成吗? Thanks in advance. 提前致谢。

Here is the export code: 这是导出代码:

$CSV = @()
get-qaduser -searchroot 'OU=Test Live,DC=domain,DC=edu' -sizelimit 0 | foreach-object {
    $attributes = get-qaduser $_ | Select-Object Name,Mail,givenName,sn,displayName
    $CSV += $attributes
}
$CSV | export-csv -path "c:\test.csv" -encoding unicode -notypeinformation

尝试此操作,它将为每个用户对象添加两个新列(属性),Action(添加)和Resource(邮箱):

Get-QADUser -SearchRoot 'OU=Test Live,DC=domain,DC=edu' -SizeLimit 0 | Select-Object @{Name='Action';Expression='Add'}},@{Name='Resource';Expression='Mailbox'}},Name,Email,GivenName,LastName,DisplayName | Export-Csv -Path c:\test.csv -Encoding Unicode -NoTypeInformation

This should produce tw new fields on the front of each row. 这应该在每行的前面产生两个新字段。 Can't test it right now though: 现在无法测试:

$CSV = @()
get-qaduser -searchroot 'OU=Test Live,DC=domain,DC=edu' -sizelimit 0 | foreach-object {
    $attributes = get-qaduser $_ | Select-Object @{n='Add';e='Add';}, @{n='Mailbox';e='Mailbox'},Name,Mail,givenName,sn,displayName
    $CSV += $attributes
}
$CSV | export-csv -path "c:\test.csv" -encoding unicode -notypeinformation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM