PowerShl список последних журналов и вставить тело письма - PullRequest
0 голосов
/ 02 февраля 2019

Здравствуйте, мне нужно отправить последний .log и вставить в $ body с get-content

$Logpath = "D:\Script\"

$LastLog = Get-ChildItem $Logpath | Where-Object {$_.LastWriteTime -gt (Get-Date).AddDays(-1)} | select-object Name -last 1

$fullpath = Write-Output $Logpath $LastLog

$body = Get-Content $fullpath | out-string

PS D:\Script\> Get-ChildItem $Logpath | Where-Object {$_.LastWriteTime -gt (Get-Date).AddDays(-1)} | select-object Name -last 1

Name                                                                                                                                                                                                                                                               
----                                                                                                                                                                                                                                                               
test05.txt

$ fullpath не работает, а $ body я не знаю, как это сделать ..

thx 4 help im noob

1 Ответ

0 голосов
/ 02 февраля 2019

Я думаю, что это может помочь вам:

$Logpath   = "D:\Script\"
$yesterday = (Get-Date).AddDays(-1)

# this will get you a FileInfo object of the latest log file
$LastLog = Get-ChildItem $Logpath -File | Where-Object {$_.LastWriteTime -gt $yesterday} | Select-Object -Last 1

# the FileInfo object has a 'FullName' property
Write-Host "Reading file '$($LastLog.FullName)'"

# to get the content as a single string, use the '-Raw' switch
$body = Get-Content $LastLog.FullName -Raw 

# to send this as email, have a look at the 'Send-MailMessage' cmdlet at
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/send-mailmessage?view=powershell-6

#basic example on 'Send-MailMessage'
Send-MailMessage -To "someone@example.com" -From "me@example.com" -Subject "Log $($LastLog.Name)" -Body $body
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...