How can I hide my password in the PowerShell script cmdlet used to migrate users to Exchange Online?

Posted on 2014-07-15
Last Modified: 2014-07-17
PowerShell Cmdlet to Migrate User to Exchange 2013 Online:

How can I hash my password (shown here as Pass123) in this cmdlet?

$cred = New-Object "", (convertTo-SecureString "Pass123" -AsPlainText -Force)
$cred1 = New-Object "wdw\3dougk035", (convertTo-SecureString "Pass123" -AsPlainText -Force)
Question by:Kati Dougherty
    LVL 38

    Accepted Solution

    Why even put the password in the script?  Just run
    $cred = Get-Credential
    to save your credentials in memory and then run your script which uses $cred.

    The only other way I know is to convert the secure string to an encrypted string which can then be saved to a file.  This file can be read in and converted back into a secure string (but only on the same machine that it was converted from a secure string) to be used in the creation of a PSCredential object.
    #outside the script, saving the encrypted password for later
    Read-Host "enter password" -AsSecureString | ConvertFrom-SecureString | Out-File password.txt
    #inside the script
    $cred = New-Object "", (Get-Content password.txt | ConvertTo-SecureString)

    Open in new window


    Author Comment

    by:Kati Dougherty
    We are using an automated script using Task scheduler.
    How do we encrypt the password in the DAILY script?

    LVL 38

    Expert Comment

    I've never tried accessing the file as a different user or scheduled task to see if it could be converted back to a secure string in that scenario, so you'd just have to test.  Create the file to save the encrypted password.
    Then run the scheduled task on the same computer to use the file and see if it works.

    Author Comment

    by:Kati Dougherty
    Thanks FooTech!

    Featured Post

    Wish Marketing would stop bothering you?

    Is your marketing department constantly asking for new email signature updates? Are they requesting a different design for every department? Do they need yet another banner added? Don’t let it get you down! There is an easy way to manage all of these requests...

    Join & Write a Comment

    Create high volume marketing opportunities using email signatures with these top 10 DOs and DON'Ts of email signature marketing.
    Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
    This video discusses moving either the default database or any database to a new volume.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now