1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| # récuperer hostname
$env:computername
$filePath = "d:\ping.log"
"le nom de la machine est $env "|add-content $filePath
# le SID de la machine
$user = New-Object System.Security.Principal.NTAccount("$env:USERDOMAIN\$env:USERNAME")
$sid = $user.Translate([System.Security.Principal.SecurityIdentifier])
$sid.AccountDomainSid.ToString()
"le SID de la machine est $sid"|add-content $filePath
# send email
$Body = Get-Content $filePath | Out-String
$user = "rafiachraf@hotmail.com"
$pass = ConvertTo-SecureString -String "mypassword" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential $user, $pass
$mailParam = @{
To = "rafiachraf91@gmail.com"
From = "Me <rafiachraf@hotmail.com>"
Subject = "File report"
Body = $body
SmtpServer = "smtp.live.com"
Port = 587
Credential = $cred
}
Send-MailMessage @mailParam -UseSsl |
Partager