Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .Synopsis
- Encrypts a password to a txt file
- .Description
- Encrypts a password to a txt file.
- If no filePath is specified it will output to '<your default folder>\$env:COMPUTERNAME\$env:USERNAME\$description.txt'
- If a filePath is specified the output will be '$filePath\$env:COMPUTERNAME\$env:USERNAME\$description.txt'
- .Parameter filePath
- Optional - String - filePath to store the encrypted key
- .Example
- Set-SecureCredentials
- .Example
- Set-SecureCredentials '\\Server1\lockedDownShare\'
- .Link
- https://mcpmag.com/articles/2017/07/20/save-and-read-sensitive-data-with-powershell.aspx
- #>
- Function Set-SecureCredentials
- {
- Param(
- [Parameter(Mandatory=$false)][string] $filePath = '\\server1\<your default folder>'
- )
- #$password = Read-Host "Password`t" -AsSecureString
- $description = Read-Host "Description`t"
- if ($filePath -eq '\\server1\<your default folder>')
- {
- $filePath += "\$env:COMPUTERNAME\$env:USERNAME\$description.xml"
- }
- else
- {
- $filePath += "\$description.xml"
- }
- New-Item -Path $filePath -ItemType "file" -Force
- Get-Credential | Export-Clixml -Path $filePath
- }
- Function Get-SecureCredentials
- {
- Param(
- [Parameter(Mandatory=$true)][string] $file
- )
- $credentials = Import-Clixml -Path $file
- Write-Output $credentials
- }
- #Declare which functions to export/make available
- Export-ModuleMember -Function 'Set-SecureCredentials'
- Export-ModuleMember -Function 'Get-SecureCredentials'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement