-
Notifications
You must be signed in to change notification settings - Fork 58
/
PoShKeePass.psm1
74 lines (57 loc) · 2.83 KB
/
PoShKeePass.psm1
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
## Unblock files
Get-ChildItem -Path $PSScriptRoot -Recurse -File | Unblock-File
## dot source all script files
Get-ChildItem -Path $PSScriptRoot -Recurse -File -Filter '*.ps1' | ForEach-Object {
if($_.DirectoryName -imatch '.+\\poshkeepass\\(functions|internal)$')
{
. $_.FullName
}
}
[String] $Global:KeePassConfigurationFile = '{0}\KeePassConfiguration.xml' -f $PSScriptRoot
[String] $Global:KeePassLibraryPath = '{0}\bin\KeePassLib_2.39.1.dll' -f $PSScriptRoot
## Source KpLib
Import-KPLibrary
## Check for config and init
if (-not(Test-Path -Path $Global:KeePassConfigurationFile))
{
Write-Warning -Message '**IMPORTANT NOTE:** Please always keep an up-to-date backup of your keepass database files and key files if used.'
$Versions = ((Get-ChildItem "$PSScriptRoot\..").Name | Sort-Object -Descending)
if(-not $(Restore-KPConfigurationFile))
{
New-KPConfigurationFile
$previousVersion = [int]($Versions[1] -replace '\.')
$CurrentVersion = $Versions[0]
if($previousVersion -lt 2124)
{
Write-Warning -Message ('**BREAKING CHANGES:** This new version of the module {0} contains BREAKING CHANGES, please review the changelog or readme for details!' -f $CurrentVersion)
}
Write-Warning -Message 'This message will not show again on next import.'
}
}
else
{
New-Variable -Name 'KeePassProfileNames' -Value @((Get-KeePassDatabaseConfiguration).Name) -Scope 'Script' #-Option Constant
}
Export-ModuleMember *
if(Get-Command Register-ArgumentCompleter -ea 0)
{
Register-ArgumentCompleter -ParameterName 'DatabaseProfileName' -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
Get-KeePassDatabaseConfiguration | Where-Object { $_.Name -ilike "${wordToComplete}*" } | ForEach-Object {
New-Object System.Management.Automation.CompletionResult ( $_.Name, $_.Name, 'ParameterValue', $_.Name)
}
}
Register-ArgumentCompleter -ParameterName 'IconName' -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
[KeePassLib.PwIcon].GetEnumValues() | Where-Object { $_ -ilike "${wordToComplete}*" } | ForEach-Object {
New-Object System.Management.Automation.CompletionResult ( $_, $_, 'ParameterValue', $_)
}
}
Register-ArgumentCompleter -ParameterName 'PasswordProfileName' -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
(Get-KPPasswordProfile).Name | Where-Object { $_ -ilike "${wordToComplete}*" } | ForEach-Object {
New-Object System.Management.Automation.CompletionResult ( $_, $_, 'ParameterValue', $_)
}
}
}
## add one for paths - can't do this until connection management is implemented.