Protect credentials in Powershell

AlexRobert 1 Reputation point
2021-12-14T10:53:19.717+00:00

I've written powershell code in that I am using username and password. I wanted to understand is there any way to protect the username name password. I am going to schedule this ps using windows task manager.

Windows for business | Windows Server | User experience | PowerShell
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2021-12-14T15:37:55.767+00:00

    You can save the credential in a file . . . the password's encrypted and can only be used on the machine on which the credential was created\saved.

    $Credential = Get-Credential
    $Credential | Export-CliXml -Path c:\junk\c.cred
    

    To use the credential:

    $Credential = Import-CliXml -Path c:\junk\c.Cred
    
    1 person found this answer helpful.

  2. Limitless Technology 39,926 Reputation points
    2021-12-14T20:59:02.177+00:00

    Hello @AlexRobert

    I would recommend the usage of the ConvertTo-SecureString cmdlet, as a way to store your password as a hashed data:

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/convertto-securestring?view=powershell-7.2

    Hope this helps with your query,

    -----------

    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.