我的powershell脚本设置如下:
$body = Get-ChildItem E:\log -File -Recurse | Where Name -Match '(\d{8})\.' |
Foreach {Add-Member -Inp $_ NoteProperty ReturnDate ($matches[1]) -PassThru} |
Group DirectoryName |
Foreach {$_.Group | Sort ReturnDate -Desc | Select -First 1 | Out-String }
$emailSmtpServer = "server"
$emailFrom = "email"
$emailTo = "email"
$emailSubject = "Testing e-mail"
$emailBody = $body
Send-MailMessage -To $emailTo -From $emailFrom -Subject $emailSubject -Body ($body|Out-String) -SmtpServer $emailSmtpServer
在日志文件夹中,我有一堆子文件夹,例如folder1,folder2,folder3。这些可能会改变所以我想设置一个配置文件,以便能够维护它们,而不是每次运行脚本时都通过整个E:\ log文件夹。
我想添加诸如
之类的内容$configfile = Get-Content -path E:\config.txt
这会输出Process1,Process2,Process3等,我不确定如何将数据放入我的脚本中,就像它当前的结构一样。任何意见,将不胜感激。我试图添加
$body = Get-Childitem E:\log\$_
到我的初始行,但那不起作用
答案 0 :(得分:1)
试试这个:
get-childitem ( get-content e:/config.txt )