Last active
October 20, 2019 18:40
-
-
Save janikvonrotz/898be0891058ee091dae8c68a8e2b91e to your computer and use it in GitHub Desktop.
Convert KeePass to Pass
#KeePass
#PowerShell
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
[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 | |
} |
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
[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