[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4310
  • Last Modified:

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 System.management.automation.PSCredential "kati.3dougherty@twdc.onmicrosoft.com", (convertTo-SecureString "Pass123" -AsPlainText -Force)
$cred1 = New-Object System.management.automation.PSCredential "wdw\3dougk035", (convertTo-SecureString "Pass123" -AsPlainText -Force)
0
Kati Dougherty
Asked:
Kati Dougherty
  • 2
  • 2
1 Solution
 
footechCommented:
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 System.management.automation.PSCredential "kati.3dougherty@twdc.onmicrosoft.com", (Get-Content password.txt | ConvertTo-SecureString)

Open in new window

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

Thanks!
KatiD
0
 
footechCommented:
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.
0
 
Kati DoughertyAuthor Commented:
Thanks FooTech!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now