/
FromPowershell.ps1
53 lines (42 loc) · 1.23 KB
/
FromPowershell.ps1
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
function ExitWithCode
{
param
(
$exitcode
)
$host.SetShouldExit($exitcode)
exit $exitcode
}
function Example
{
$options = [pscustomobject]@{
FieldNames = @('extra field 1', 'extra password 1')
AttachmentNames = @('example_attachment.txt')
}
$object = KeePassEntry -title "Sample Entry" -options $options
if ($object -eq $null) {
Write-Host "KeePass is not started"
Write-Host "Has KeePassCommander.dll been copied to the directory containing KeePass.exe ?"
return 2
}
$object | Out-String | Write-Host
return 0
}
# find KeePassEntry.ps1
$KeePassEntry_ps1 = Join-Path -Path $PSScriptRoot -ChildPath "KeePassEntry.ps1"
if (-Not (Test-Path $KeePassEntry_ps1)) {
$KeePassEntry_ps1 = Join-Path -Path $PSScriptRoot -ChildPath "..\bin\release\KeePassEntry.ps1"
if (-Not (Test-Path $KeePassEntry_ps1)) {
Write-Host "KeePassEntry.ps1 not found"
ExitWithCode -exitcode 1
}
}
# include KeePassEntry.ps1 containing function KeePassEntry
. $KeePassEntry_ps1
# BEGIN example
$exitcode = Example
# END example
# remove included function KeePassEntry
Remove-Item function:\KeePassEntry
#exit
ExitWithCode -exitcode $exitcode