0

这行得通,但是...

$EmailFrom = "vsphere@nasa.gov"
$EmailTo = "userwithOLDsnapshot@nasa.gov" 
$Subject = "Notification" 
$Body = "this is a notification for your snapshot"
$SMTPServer = "smtp.gmail.com" 
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) 
$SMTPClient.EnableSsl = $true 
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("username", "password"); 
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

反正有没有用凭证商店做这个?以明文形式在脚本中嵌入凭据是不行的。

4

1 回答 1

0

以下将创建一个加密字符串。您可以将此输出保存到某个文件并稍后读取: $securePWord=Read-Host "Enter some password" -AsSecureString

这会将 SecureString 转换为可用文本: $pWord=[System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($securePWord))

于 2012-05-21T14:39:36.377 回答