Skip to content

Commit 04b54e6

Browse files
authored
Create Store-SecurestringToFile.ps1
1 parent 3f3dced commit 04b54e6

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
param(
2+
[Parameter(Mandatory=$true)]
3+
[string]$Path,
4+
[Parameter(Mandatory=$true)]
5+
[string]$password
6+
)
7+
8+
# Convert the password to a secure string
9+
$SecurePassword = $password | ConvertTo-SecureString -AsPlainText -Force
10+
11+
# Store the credential in the path
12+
$SecurePassword | ConvertFrom-SecureString | Out-File $Path
13+
14+
# Write What we did
15+
Write-Host "Wrote password to $path"
16+
17+
<#
18+
.SYNOPSIS
19+
Stores a password in a file on the local computer for retrevial by scripts.
20+
21+
.DESCRIPTION
22+
Used for securely storing a password on a machine for use with automated scripts.
23+
24+
Takes a password and encrypts it using the local account, then stores that password in a file you specify.
25+
Only the account that creates the output file can decrypt the password stored in the file.
26+
27+
.PARAMETER Path
28+
Path and file name for the password file that will be created.
29+
30+
.PARAMETER Password
31+
Plain text version of password.
32+
33+
.OUTPUTS
34+
File Specified in Path variable will contain an encrypted version of the password.
35+
36+
.EXAMPLE
37+
.\Store-SecurestringToFile.ps1 -Path c:\scripts\scriptname.key -Password "Password123"
38+
39+
Puts the encrypted version of Password123 into the c:\scripts\scriptname.key file
40+
#>

0 commit comments

Comments
 (0)