我是PowerShell的新手。以下是我的要求:
读取 csv 日志文件并根据电子邮件字段,我必须查询并将结果导出到 csv 文件。
下面是一个示例日志文件:
emailid,日期,时间,client_ip,client_hostname,server_ip,server_hostname,source,event_id manu@ionidea.com,05-24-2012,11:12:00,23.3.45.678,tytytyty,12.21.3.45,yuyuyuyuyu,hrertythghhdgfh,00928 ram@ionidea.com,06-05-2012,11:14:23,91.45.78.980,juqawessjj,16.51.5.93,pmbctr,ioyrhrtgdgdggdgjhjhj,00929 sheetal@ionidea.com,07-10-2012,11:12:00 ,10.0.87.369,yturbctyt,10.34.0.788,kokolioimdgf,brytifvnbty,00930
我正在使用以下脚本来执行此操作:
function saveAndRun(){
$var_newJob = $window.FindName("txtbox_JobName").Text+".txt";
write-host $var_newJob
$varArray_emailIds = ($window.FindName("txtbox_Email").Text).split(',');
$var_fromDate = "'"+ $window.FindName("txtbox_FromDate").Text+"'";
$var_toDate = "'"+$window.FindName("txtbox_ToDate").Text+"'";
$list="";
ForEach($var_emailid in $varArray_emailIds){
$emailid = "'"+$var_emailid+"'";
ForEach-Object{
Import-Csv D:\Manu\Xtract\Log\MSLogFile.txt | Where-Object {$_.emailid -eq $emailid -and ($_.date -ge $var_fromDate -and $_.date -le $var_toDate ) }
} | Export-Csv -Path D:\Manu\Xtract\extract\$var_newJob
}
}