locked
Store password in Powershell script RRS feed

Answers

  • THe easiest way to save credentials is this:

    $creds=Get-Credential yourdomain\yourid
    $creds | Export-CLiXml secure.clixml

    Now just load it in your scripts:

    $creds=Import-CliXml secure.clixml
    Invoke-Command { do something} -Computer somepc -Credential $creds

    In all cased the credentials saved can only be used by you from your account while you are logged in.  You cannot pass saved credentials to another user.  This is by design as it would be a security problem to pass credentials as there is no method to securely save credentials and hide them from anyone who can use them.


    \_(ツ)_/


    • Edited by jrv Tuesday, April 12, 2016 5:33 PM
    • Proposed as answer by Elaine Jing Wednesday, April 13, 2016 8:51 AM
    • Marked as answer by Elaine Jing Wednesday, April 20, 2016 2:49 AM
    Tuesday, April 12, 2016 11:20 AM
  • As an alternative, if you don't want extra files laying around.  you can store the password, encrypted, within the script.

    http://blog.coretech.dk/rja/store-encrypted-password-in-a-powershell-script/

    • Proposed as answer by Elaine Jing Wednesday, April 13, 2016 8:52 AM
    • Marked as answer by Elaine Jing Wednesday, April 20, 2016 2:49 AM
    Tuesday, April 12, 2016 5:30 PM

All replies

  • THe easiest way to save credentials is this:

    $creds=Get-Credential yourdomain\yourid
    $creds | Export-CLiXml secure.clixml

    Now just load it in your scripts:

    $creds=Import-CliXml secure.clixml
    Invoke-Command { do something} -Computer somepc -Credential $creds

    In all cased the credentials saved can only be used by you from your account while you are logged in.  You cannot pass saved credentials to another user.  This is by design as it would be a security problem to pass credentials as there is no method to securely save credentials and hide them from anyone who can use them.


    \_(ツ)_/


    • Edited by jrv Tuesday, April 12, 2016 5:33 PM
    • Proposed as answer by Elaine Jing Wednesday, April 13, 2016 8:51 AM
    • Marked as answer by Elaine Jing Wednesday, April 20, 2016 2:49 AM
    Tuesday, April 12, 2016 11:20 AM
  • Missing an, S, in your 2nd command.. :)

    $creds=Get-Credential yourdomain\yourid
    $creds | Export-CLiXml secure.clixml

    Tuesday, April 12, 2016 5:26 PM
  • As an alternative, if you don't want extra files laying around.  you can store the password, encrypted, within the script.

    http://blog.coretech.dk/rja/store-encrypted-password-in-a-powershell-script/

    • Proposed as answer by Elaine Jing Wednesday, April 13, 2016 8:52 AM
    • Marked as answer by Elaine Jing Wednesday, April 20, 2016 2:49 AM
    Tuesday, April 12, 2016 5:30 PM