-
-
Save curi0usJack/1fd3378eb6d0592720f13f7e3302f5b6 to your computer and use it in GitHub Desktop.
Wraps Secret Server Decryption routine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Invoke-SecretWrap | |
{ | |
Param ( | |
[Parameter(Mandatory = $True )] | |
[String] $EncryptionConfigPath, | |
[Parameter(Mandatory = $True )] | |
[String] $SecretServerDataPath | |
) | |
$raw = Import-csv $SecretServerDataPath | |
# Filter out anything that doesn't have valid keys, ivs, or ivmeks | |
$data = $raw | ?{$null -ne $_.Key -and $null -ne $_.ItemValue -and $null -ne $_.IV ` | |
-and $null -ne $_.IvMEK -and $_.IV.length -gt 10 -and $_.Key.Length -gt 10} | |
$collection = @() | |
foreach ($entry in $data) { | |
try { | |
$plain = Invoke-SecretDecrypt -EncryptionConfig $EncryptionConfigPath -ItemIV $entry.IV ` | |
-Item $entry.ItemValue -IVMek $entry.IVMek -Key $entry.Key -NewFormat | |
$name = $entry.SecretName | |
$plain = $plain.Replace("`r`n", " ") | |
$temp = new-object psobject -Property @{ | |
Name = $name | |
Description = $desc | |
Decrypted = $plain | |
} | |
Write-Output "$name,$desc,$plain" | |
$collection += $temp | |
} | |
catch { | |
# After you've done enough testing, you still might get sporadic errors on the occasional item. | |
# Comment out the throw below to ignore & proceed. | |
throw | |
} | |
} | |
$collection | Export-Csv "awwyeah.csv" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment