-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathRead-DPEncryptedContent.ps1
More file actions
41 lines (36 loc) · 1.01 KB
/
Read-DPEncryptedContent.ps1
File metadata and controls
41 lines (36 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<#
.SYNOPSIS
returns the contents of an encrypted file in the user area.
.DESCRIPTION
This PowerShell routine will fetch the contents of a file
containing an encrypted object stored in an XML Document
This is encrypted as a system.secure.string. It converts
it back into plain text
.PARAMETER Filename
A description of the Server parameter.
.NOTES
Additional information about the function.
#>
function Read-DPEncryptedContent
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
HelpMessage = 'The File to decrypt')]
$Filename
)
$secureString = Import-Clixml $Filename
$bstrPtr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($secureString)
try
{
$originalText = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstrPtr)
}
Catch { write-error "sadly we couldn't get the unencrypted contents of $Filename" }
finally
{
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstrPtr)
}
Write-Output $originalText
}