Skip to content

Instantly share code, notes, and snippets.

@ecspresso
Created May 26, 2020 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecspresso/7d9df4fc706f306ca2b3735dcc29a0b9 to your computer and use it in GitHub Desktop.
Save ecspresso/7d9df4fc706f306ca2b3735dcc29a0b9 to your computer and use it in GitHub Desktop.
Autoupdate KeePassOTP for KeePass (for any version of PowerShell edition)
$updateurl = 'https://firebasestorage.googleapis.com/v0/b/rookiestyle-43398.appspot.com/o/versioninfo.txt?alt=media&token=89da60c0-f331-4334-94bb-0dccf617818f'
$iwr = (New-Object System.Net.WebClient).DownloadString($updateurl)
$version = ($iwr.split() | Select-String '^KeePassOTP') -replace 'KeePassOTP:',''
if(-not (Test-Path -Path 'HKCU:\Software\keepass')) {
New-Item -Path 'HKCU:\Software\keepass' -ItemType Directory
}
try {
$keepassotp = (Get-ItemProperty -Path 'HKCU:\Software\keepass\' -Name 'keepassotp' -ErrorAction Stop).keepassotp
} catch {
New-ItemProperty -Path 'HKCU:\Software\keepass\' -Value 0 -PropertyType String -Name 'keepassotp'
$keepassotp = (Get-ItemProperty -Path 'HKCU:\Software\keepass\' -Name 'keepassotp' -ErrorAction Stop).keepassotp
}
if($keepassotp -ne $version) {
& "${env:ProgramFiles(x86)}\KeePass Password Safe 2\KeePass.exe" --exit-all
(New-Object System.Net.WebClient).DownloadString('https://netix.dl.sourceforge.net/project/keepassotp/KeePassOTP.plgx') | Out-File "${env:ProgramFiles(x86)}\KeePass Password Safe 2\Plugins\KeePassOTP.plgx"
Set-ItemProperty -Path 'HKCU:\Software\keepass\' -Name 'keepassotp' -Value $version
& "${env:ProgramFiles(x86)}\KeePass Password Safe 2\KeePass.exe"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment