Error
New-Object : Cannot find an overload for "PSCredential" and the argument count: "2". At D:\Scripts\gsend.ps1:12 char:15
Code
#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
$EmailUsernameor$EncryptedPW. As Olaf says, this PSCredentials takes a string username and secure string password.$EncryptedPWisn't a secure string.