Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert KeePass to Pass #KeePass #PowerShell
[xml]$Content = Get-Content -Path "KeepassData.xml"
<#
Access the xml data:
Content.KeePassFile.Root.Group.Group.Entry[67].String[0].Value
#>
function Traverse-Tree ($Node, $ParentPath) {
$Path = $ParentPath + "/" + $Node.Name
$ChildNodes = $Node.Group
$Entries = $Node.Entry | Where-Object { $_.Times.Expires -eq "False" }
if($Entries -and ($Node.Name -notcontains "Recycle Bin")) {
foreach ($Entry in $Entries) {
$Content = ""
$Title = ""
$Password = ""
foreach ($Field in $Entry.String) {
switch($Field.Key) {
"Title" { $Title = $Field.Value }
"Password" { $Password = $Field.Value.'#text' }
"Notes" {
$Content += "$($Field.Key): $(($Field.Value -replace "\n","\n" ) -replace ":", "=")`n"
Write-Host $Content
}
default {
$Content += "$($Field.Key): $($Field.Value -replace "\n","\n" )`n"
}
}
}
@{
Path = ($Path + "/" + $Title) -replace " ", "_"
Content = $Password + "`n" + $Content
}
}
}
if($ChildNodes) {
foreach ($ChildNode in $ChildNodes ) {
Traverse-Tree $ChildNode $Path
}
}
}
$Content.KeePassFile.Root.Group.Group | ForEach-Object {
Traverse-Tree -Node $_ -ParentPath ""
} | ForEach-Object {
Write-Host "Creating pass entry: $($_.Path)"
Write-Host $_.Content
$_.Content | & pass insert -m $_.Path
}
[xml]$Content = Get-Content -Path "KeepassData.xml"
$Entries = $Content.KeePassFile.Root.Group.Group | Where-Object { $_.Times.Expires -eq "False" -and $_.Name -eq "Private" } | %{$_.Entry}
$Entries | % {
$String = $_.String | where{$_.Value -eq "GitHub"}
if($String) {
$_.String | %{
if($_.Key -eq "2FA App Passcode") {
$_.Value -replace "\n","\n"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.