public/Merge-KeePassGroups.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

function Merge-KeePassGroups () {
    Param(
        [Parameter(ValueFromPipeline = $True)]
        [NerdyMishak.KeePass.IKeePassPackage] $Package,

        [Parameter(Position = 0)]
        [String] $Path,
        
        [Parameter(Position = 1)]
        [String] $GroupName,
        
        [Switch] $Force 
    )

    $srcPackage = $Package | Open-KeePassKdbxLink $Path
    
    $srcGroup = $srcPackage.FindGroup($Path);
    if($srcGroup -eq $null) {
        Write-Warning "Could not find Group from source package: $Path"
        return;
    }
    $destGroup = $Package.FindGroup($Path);
    $srcGroup.MergeTo($destGroup, $Force.ToBool())
   

    $srcPackage.Dispose();

}