PowerShell/VBScript/Other 中的自动化:根据 excel 中的日期值通过 mail/other 进行提醒

Automation in PowerShell/VBScript/Other : Reminder via mail/other based on date value in excel

一个excel文件(名称:test.xls)包含n行, n 不是固定值。

excel 中有 3 列,其中包含数据(A、B、C)。 B 列的值始终是日期(格式:MM/DD/YYYY)。

需要比较 currentDate (SYSDATE) 和 B 中的值对于 excel 中的每一行,如果有的话匹配,然后将该特定记录的 A、B、C 的值通过邮件发送到地址 abc@xyz.com & cde@xyz.com,主题为 temp

如果有多个匹配项,即超过 1 行,例如 2,日期为 currentDate 然后在同一封邮件中为两行发送 A、B、C 的值。

有没有办法每天自动 运行 这个脚本?将放置此脚本的相关计算机可能已打开、关闭或注销。多数情况下会注销,很少关机(所以在启动文件夹中添加无效)。

最好不要关闭计算机,否则您必须使用 WoL 将其唤醒。

您应该创建一个即使在用户未登录时也能运行的计划任务:

下面是供您参考的示例脚本,我实际上并没有将值添加到电子邮件正文中 - 您需要根据自己的需要进行修改:

$file = "C:\Users\Vincent\Desktop\test.xls"

$body = @"
Following data was found in report:

"@

#XL const
$xlValues = -4163 
$xlPart = 2

$Excel = New-Object -ComObject excel.application
$Excel.visible = $false
$Workbook = $Excel.Workbooks.open($file) 

#Sheets(1)
$Worksheet = $Workbook.Sheets.Item(1)
#Column B
$colBRange = $Worksheet.Columns.Item(2)

#match returns error if nothing found, easier to use Find function
#$Worksheet.Application.WorksheetFunction.Match((Get-Date),$colBRange)

$dateString = [string](get-date -DisplayHint Date -Format "dd/MM/yyyy")

#.Find(What:="05/05/2015", After:=ActiveCell, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
$result = $colBRange.Find($dateString, $worksheet.Cells.Item(1,2), $xlValues)
#save address of first found cell to detect when find function wraps around
$first = $result

$continue = $result -ne $null
while ($continue){
    #work with result, like collect them
    write "Found matching date in row $($result.Row) of $($Worksheet.Name)"

    #prepare email body:
    $body = $body + ""
    $result = $colBRange.FindNext($result) #find next after current result
    $continue = ($result.Address() -ne $first.Address())
}

$PSEmailServer = "smtp.mydomain.com"

Send-MailMessage -From "no-reply@mydomain.com" `
    -To "me@mydomain.com" `
    -Subject "Report" `
    -Body $body