新对象:无法找到 “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 –