我正在寻找一种与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
批处理文件中引用的worec.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,但还没有弄明白。 (编程不是我的事情,如果我需要返回并添加其他注释,请告诉我。)
答案 0 :(得分:1)
折叠在管道上以便于阅读:
$compared = Compare-Object $current $master -Property "WO#" -PassThru |
Where-Object{$_.SideIndicator -eq '<='} |
foreach {($_.EQName,$_.EQLoc,$_.Remark,$_.Time,"`n") | out-string}