首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >搜索文本文件中的电子邮件字符串

问搜索文本文件中的电子邮件字符串
EN

Stack Overflow用户
提问于 2016-01-26 18:26:48
回答 2查看 1.6K关注 0票数 0

每天我都需要在“销售总量:”之后搜索这个数字,然后发邮件给它。我很乐意自动化这个繁琐的任务(最好使用PowerShell)。

有谁能帮我拿个示例脚本吗?该脚本将在WindowsServer2012R2上使用PowerShell 3.0运行。

示例文本文件

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-01-27 09:22:52

下面的代码非常适合我:

代码语言:javascript
复制
$finds = Select-String -Path "file path" -Pattern "text to search" | ForEach-Object {$_.Line}

Send-MailMessage -To "email.address", -From "email.address" -Subject "subject" -body $finds[-1] -SmtpServer "smtp address" here

注意:[-1] (仅显示最后一行) ForEach-Object {$_.Line}移除文件名和行号

票数 0
EN

Stack Overflow用户

发布于 2016-01-26 19:19:56

用于搜索字符串的Powershell脚本:

代码语言:javascript
复制
###########################################################
$Path = "C:\temp"
$Text = "SALES TOTAL"
$PathArray = @()
$Results = "C:\temp\test.txt"

# This code snippet gets all the files in $Path that end in ".txt".
Get-ChildItem $Path -Filter "*.txt"” |
Where-Object { $_.Attributes -ne "“Directory"} |
ForEach-Object {
If (Get-Content $_.FullName | Select-String -Pattern $Text) {
$PathArray += $_.FullName
$PathArray += $_.FullName
}
}
Write-Host "Contents of ArrayPath:"
$PathArray | ForEach-Object {$_}


##########################################################

然后参考这个文章来映射邮件的发送(因为我不确定您将使用哪个邮件客户端)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35021104

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档