matrixcombat
24-05-2017, 09:14
Добрый день!
Получив информацию из get-winevent и записав ее переменную $Event не получается передать переменную дальше
Import-Module activedirectory
$Event=(Get-WinEvent -FilterHashtable @{LogName=”Security”;ID=4720} -MaxEvents 1).Properties[0]
get-aduser -f * -properties sAMAccountName, name, company, title, ipPhone, mail, telephonenumber | where {$_.SAMAccountName –like "$Event"} | foreach{
$name = $_.Name
$mail = $_.Mail
$title = $_.Title
$ipphone = $_.Ipphone
$company = $_.Company
$file = "C:\tmp\Регламент.docx"
$tnumber = $_.Telephonenumber
$Subject = "Регламент $company"
$Body = "$name $company $title $tnumber $ipphone $mail"
$secpasswd = ConvertTo-SecureString "123456" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ("send", $secpasswd)
$encoding = [System.Text.Encoding]::UTF8
send-mailmessage -from "1234@local.local" -to "$mail" -Subject "$Subject" -body "$Body" -BodyAsHtml -Attachment $file -smtpserver local.local -credential $mycreds -Encoding $encoding
}
Может кто подсказать что делаю не так?
Получив информацию из get-winevent и записав ее переменную $Event не получается передать переменную дальше
Import-Module activedirectory
$Event=(Get-WinEvent -FilterHashtable @{LogName=”Security”;ID=4720} -MaxEvents 1).Properties[0]
get-aduser -f * -properties sAMAccountName, name, company, title, ipPhone, mail, telephonenumber | where {$_.SAMAccountName –like "$Event"} | foreach{
$name = $_.Name
$mail = $_.Mail
$title = $_.Title
$ipphone = $_.Ipphone
$company = $_.Company
$file = "C:\tmp\Регламент.docx"
$tnumber = $_.Telephonenumber
$Subject = "Регламент $company"
$Body = "$name $company $title $tnumber $ipphone $mail"
$secpasswd = ConvertTo-SecureString "123456" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ("send", $secpasswd)
$encoding = [System.Text.Encoding]::UTF8
send-mailmessage -from "1234@local.local" -to "$mail" -Subject "$Subject" -body "$Body" -BodyAsHtml -Attachment $file -smtpserver local.local -credential $mycreds -Encoding $encoding
}
Может кто подсказать что делаю не так?