新對象:無法找到 「PSCredential的」 過載和 爭論數: 「2」。在d:\腳本\ gsend.ps1:12字符:15
代碼
#Create Password File (Only need once)
#$Credential = Get-Credential
#$Credential.Password | ConvertFrom-SecureString | Set-Content "D:\scripts\gsendcred.txt"
#Send Email
$EncryptedCredential = "D:\scripts\gsendcred.txt"
$EmailUsername = "[email protected]"
$EncryptedPW = Get-Content "D:\scripts\gsendcred.txt"
$EncryptedCredential = ConvertTo-SecureString -String $EncryptedCredential -
AsPlainText -Force
$Credential = New-Object Management.Automation.PSCredential ($EmailUsername,
$EncryptedPW)
$EmailFrom = "[email protected]"
$EmailTo = "[email protected]"
$EmailSubject = "GSEND Test Subject"
$EmailBody = "Test Body"
$SMTPServer = "smtp.gmail.com"
$SMTPPort = 587
$SMTPSsl = $true
這是我收到的錯誤:新對象:無法找到「PSCredential的」和參數計數過載:「2」。 在D:\ Scripts \ gsend.ps1:12 char:15 –
歡迎來到SO。請閱讀以下內容,然後再向SO發佈更多內容:https://stackoverflow.com/help/asking –
使用您的$ EncryptedCredential而不是$ EncryptedPW,PSCredential對象需要SecureString –