It is not safe to keep credentials in script but you can use next scheme:
- Run PS console and execute next 4 commands.
1.1. Generate secure key for encryption (keep it). It is simple key example:
[byte[]] $key = (1..32)
1.2. Make secured string from your password:
$SecuredString = ConvertTo-SecureString -AsPlainText -Force -String "fjuksAS1337"
1.3. Make encrypted string using secure key:
$EncryptedString = ConvertFrom-SecureString -key $key -SecureString $SecuredString
1.4. Print and keep value of $EncryptedString
:
76492d1116743f0423413b16050a5345MgB8ADQANgBLAGgAawBKADIANQBSADEAbABBAGEATgBrAHAASgBKAGcAZwBBAFEAPQA9AHwANwA2ADcAMQAzADcAOQBlAGEAZAA2AGMAMAAyADEANwBhAGIAYgBlADQAOABmAGEANABjADgAYQAzAGYAZAA2AGMAYgAxADUAMgA0ADAAMAAxADAAOQA5AGIAYwAxADQAOQAxADEANQAwADAAYQA1AGIAYgA0ADIAZAA5ADMANQA=
Use encrypted password value in your script (1.4.):
$EncryptedString = "76492d1116......ANQA="
Use secure key in your script (1.1.):
[byte[]] $key = (1..32)
Make secured string in script:
$SecuredString = ConvertTo-SecureString $EncryptedString -Key $key
Use secured string in script:
Unlock-BitLocker -MountPoint "E:" -Password $SecuredString