2012-12-21 62 views
0

先前問題的第2部分here - 我知道有一個變量,它包含明文密碼和純文本密碼的用戶名,恰好是電子郵件地址。我需要使用這些以便通過PowerShell中的SMTP發送電子郵件,例如Send-MailMessage。Powershell - 通過憑證

所以我需要通過它:

[email protected]$password

爲了對智能主機驗證發送電子郵件。任何這樣做的方式,Get-Credential或Send-MailMessage上的某些開關都很巧妙,還是有另一個完全不同的選擇?

乾杯

+0

快速搜索給出了這樣的:http://stackoverflow.com/questions/6239647/using- powershell-credentials-without-being-being-offered-for-a-password。請檢查以'$ cred'開頭的行並將其提供給send-mailmessage -credential –

回答

2

您可以使用ConvertTo-SecureString轉換您的明文密碼。

假設您的用戶名是$username變量,明文密碼在$password,你可以做這樣的事情:

$securepass = ConvertTo-SecureString -AsPlainText -String $password -Force 
$creds = New-Object System.Management.Automation.PSCredential -argumentlist $username,$securepass 

Send-MailMessage ... -Credentials $creds 
相關問題