简体   繁体   English

Exchange Powershell导出-csv

[英]Exchange powershell Export-csv

First off just a little warning that my PowerShell skills are very limited, so I may be re-inventing the wheel and doing it badly. 首先,我会稍微警告一下我的PowerShell技术非常有限,因此我可能会重新发明轮子并做得不好。

Anyway to the point I'm trying to create/run a script to pull all records of delivered mail to all accounts using the message tracking log. 无论如何,我正在尝试创建/运行脚本以使用邮件跟踪日志将传递的邮件的所有记录拉到所有帐户。 The issue I'm having is when exporting my results to csv it almost seems as if the results are encrypted. 我遇到的问题是将结果导出到csv时,结果似乎已经加密了。 Below is the code I've managed to piece together: 以下是我设法拼凑的代码:

$msg = Get-TransportServer server_to_query | Get-MessageTrackingLog -ResultSize Unlimited -Start "10/01/2014 10:00:00" -End "10/01/2014 11:00:00" -EventID deliver | select-object -ExpandProperty Recipients | Group-Object | sort count -desc | ft -auto  

Now I know it gives me the information I want as when I do the below it displays the first 10 records as well as how many in total. 现在,我知道它为我提供了我想要的信息,因为当我执行以下操作时,它将显示前10条记录以及总数。

$msg.count
$msg | select -first 10

However when i do the below its not exporting it to anything at even looks close. 但是,当我执行以下操作时,即使不将其导出到任何内容,它看起来也很接近。

$msg | Export-CSV export.csv 

Its most likely to be really basic what im missing or not understanding however I feel like I'm going round in cycles now. 它最有可能是我缺少或不了解的最基本的东西,但是我觉得我现在正在循环中。 Any pointers in the right direction would be great. 任何指向正确方向的指针都将是很好的。

Thanks Mark 谢谢马克

Your main issue is that you populate $msg with results for format-table . 您的主要问题是在$msg填充了format-table结果。 Almost anyone would say that it is fine for shell ouput only. 几乎任何人都说仅外壳输出是可以的。 If you ever intend to do anything else with the data Format-Table is not the way to go. 如果您打算对数据Format-Table做其他任何事情,那是不可行的。 First, remove the ft -auto 首先,删除ft -auto

$msg = Get-TransportServer server_to_query | Get-MessageTrackingLog -ResultSize Unlimited -Start "10/01/2014 10:00:00" -End "10/01/2014 11:00:00" -EventID deliver | select-object -ExpandProperty Recipients | Group-Object | sort count -desc

After that it will export better but you will see things like this in your csv: 之后,它会更好地导出,但是您会在csv中看到以下内容:

"System.Collections.ArrayList","17","System.Collections.ObjectModel.Collection`1[System.Management.Automation.PSObject]"

Since most of this data is just an email address repeated over and over i would wonder if you export should be something like this. 由于大多数数据只是一遍又一遍地重复发送的电子邮件地址,我想知道您是否应该导出类似这样的内容。

$msg | select name,count -first 10 | Export-Csv c:\temp\test.csv

Dont know if that is the output you are going for but it looks like it is. 不知道这是否是您要的输出,但看起来像是。

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

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