0

我正在寻找一种方法来做与 相同的事情Format-Table -HideTableHeaders,除了Format-List,我环顾四周......但没有找到任何解决方案。

背景,我一遍又一遍地导入相同的 csv,但随着时间的推移,将添加新行。当它们出现时,我将发送一封包含新信息的电子邮件。以下是我自己提出的难题的各个部分:

##### send email-workorder.ps1 #####
$smtpServer = "smtp.acme.com"
$current = import-csv .\current.csv -Delimiter "|" -header 'WO#', 'WO Cat', 'EQ#', 'EQName', 'EQLoc', 'Remark', 'Date', 'Time', 'Requestor'
$master = import-csv .\master.csv -Delimiter "|" -header 'WO#', 'WO Cat', 'EQ#', 'EQName', 'EQLoc', 'Remark', 'Date', 'Time', 'Requestor'
$compared = Compare-Object $current $master -Property  "WO#" -PassThru |  Where-Object{$_.SideIndicator -eq '<='} | Select-Object 'EQName', 'EQLoc', 'Remark', 'Time' | Format-List | Out-String

if ($compared) {
# Send E-Mail
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)

$msg.From = "workorder@acme.com"
$msg.To.Add("mechanic@acme.com")
$msg.Subject = "New WO Submitted"
$msg.Body = $compared

$smtp.Send($msg) }

将调用 powershell 脚本的批处理文件:

##### email-workorder.bat #####
##### this will be called by a scheduled task, set to run every five minutes #####
cd c:\scripts
sqlcmd -E -S acme-workorder-server -d WORDERDB -i worec.sql -h-1 -o "current.csv" -W -s "|"
powershell.exe -command .\email-workorder.ps1
move /y current.csv master.csv
exit

批处理文件中引用的 wearc.sql 文件:

##### worec.sql #####
set nocount on;
SELECT * FROM (
SELECT top 1000 [WONUMB]
      ,[WORKCAT]
      ,[EQNUMB]
      ,[EQNAME]
      ,[EQLOC]
      ,[REMARK]
      ,CAST([DATEISSUED] As DATE) As DATEISSUED
      ,CAST([TIMEISSUED] As TIME(0)) As TIMEISSUED
      ,[REQUESTEDBY]
  FROM [WORDERDB].[dbo].[WHREC]
  WHERE ( WORKCAT = 'BRK' Or
        WORKCAT = 'SAF' Or
        WORKCAT = 'CPU' Or      
        WORKCAT = 'COR' ) And
        WOCLOSED = 'N'
  ORDER BY [WONUMB] desc ) x
  ORDER BY [WONUMB] asc

现在它发出的电子邮件是这样的:

EQName : PREP           
EQLoc  : NULL
Remark : need blown bulbs replaced@checkers 
Time   : 16:40:00

EQName : LIFT TRUCK 9         
EQLoc  : PREP 
Remark : guard obstructing view and probe no
Time   : 17:57:00

EQName : WASHER #2            
EQLoc  : PREPARATION 
Remark : sat 1 has 2 leaks and sat 2 has 2 l
Time   : 22:38:00

EQName : FINISHING 
EQLoc  : NULL
Remark : Need to repair pump on first statio
Time   : 19:05:00

EQName : FINISHING  
EQLoc  : NULL
Remark : SKY BAR NEEDS CLEANING 
Time   : 13:12:00

这很好,除了我想摆脱左边的标题而只拥有实际信息。这将通过手持收音机上的短信发送,所以我希望尽可能少地发送信息。我也想摆脱 Hh:mm:00 ,但还没有弄清楚。(编程不是我的事,如果我需要返回并添加其他评论,请告诉我。)

4

1 回答 1

2

为了便于阅读,在管道处折叠:

$compared = Compare-Object $current $master -Property  "WO#" -PassThru |
Where-Object{$_.SideIndicator -eq '<='} |
foreach {($_.EQName,$_.EQLoc,$_.Remark,$_.Time,"`n") | out-string}
于 2013-10-18T18:21:13.657 回答