none
When I use the send-mailmessage and do -credential how to get my password in without having to type it in? RRS feed

Answers

  • Well, the password has to come from somewhere. Are you planning to save it in your script, accepting the risk involved with a plain text password like that?  Or do you want to enter it once, and save it for future executions?

    If it's the latter, you can set up a credential object like this:

    $cred = Get-Credential
    
    $cred | Export-CliXml -Path $home\SavedCredential.xml

    The password in that XML file will be encrypted using DPAPI; only your account will have the keys to decrypt it (and only on the same computer where you encrypted it.)  To read it back in and use later:

    $cred = Import-CliXml -Path $home\SavedCredential.xml
    
    Send-MailMessage -Credential $cred #...


    • Edited by David Wyatt Friday, January 24, 2014 7:07 PM
    • Marked as answer by bohlingj Friday, January 24, 2014 7:16 PM
    Friday, January 24, 2014 7:06 PM

All replies

  • Well, the password has to come from somewhere. Are you planning to save it in your script, accepting the risk involved with a plain text password like that?  Or do you want to enter it once, and save it for future executions?

    If it's the latter, you can set up a credential object like this:

    $cred = Get-Credential
    
    $cred | Export-CliXml -Path $home\SavedCredential.xml

    The password in that XML file will be encrypted using DPAPI; only your account will have the keys to decrypt it (and only on the same computer where you encrypted it.)  To read it back in and use later:

    $cred = Import-CliXml -Path $home\SavedCredential.xml
    
    Send-MailMessage -Credential $cred #...


    • Edited by David Wyatt Friday, January 24, 2014 7:07 PM
    • Marked as answer by bohlingj Friday, January 24, 2014 7:16 PM
    Friday, January 24, 2014 7:06 PM
  • Your the man, Great info.
    Friday, January 24, 2014 7:16 PM