简体   繁体   English

PowerShell在输出CSV中包含输入变量

[英]PowerShell include input variable in output CSV

I was hoping someone could help with what I thought was somthing simple. 我希望有人能帮助我以为简单的事情。 I have a PowerShell script that reads a file of email addresses then executes an Exchange O365 command and creates a CSV file. 我有一个PowerShell脚本,该脚本读取电子邮件地址文件,然后执行Exchange O365命令并创建CSV文件。 This works great. 这非常有效。 However, I was hoping to include in the output line the contents of the variable used in the input. 但是,我希望在输出行中包含输入中使用的变量的内容。 In other words possibly concatenate it to the output of the command. 换句话说,可能将其连接到命令的输出。

$Emails = Get-Content "C:\Allqueue.csv"

foreach ($Email in $Emails) {
    Get-MoveRequest $Email |
        select displayname, alias, UserPrincipalName |
        Export-Csv -Append "C:\AllqueueResults.txt"
}

Unfortunately, the Get-Mailbox results do not include the email address, so it can't be used in the select statement. 不幸的是, Get-Mailbox结果不包含电子邮件地址,因此不能在select语句中使用它。

My initial attempt was to just add $Email to the select statement like this. 我最初的尝试是像这样将$Email添加到select语句中。

select displayname, alias, UserPrincipalName, $Email

But that just created a column. 但这只是创建了一个列。

Any help would be greatly appreciated. 任何帮助将不胜感激。

您可以使用带有计算属性的电子邮件地址添加新列:

select displayname, alias, UserPrincipalName, @{n='Email';e={$Email}}

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

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