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

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)
Kati DoughertyCollaboration ArchitectAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kati DoughertyCollaboration ArchitectAuthor Commented:
We are using an automated script using Task scheduler.
How do we encrypt the password in the DAILY script?

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.
Kati DoughertyCollaboration ArchitectAuthor Commented:
Thanks FooTech!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.