-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththycotic-secretserver-to-bitwarden.ps1
42 lines (39 loc) · 1.49 KB
/
thycotic-secretserver-to-bitwarden.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
# Converts XML export from Thycotic SecretServer to Bitwarden JSON import format
# Ref: https://bitwarden.com/help/condition-bitwarden-import/
$secretServerExportXML = "$HOME\Downloads\export.xml"
$bitwardenImportJSON = "$HOME\Desktop\bitwarden-import.json"
$items = @()
Select-Xml -Path $secretServerExportXML -XPath '//Secrets/Secret' | ForEach-Object {
$item = [PSCustomObject]@{
"type" = 1
"name" = $_.Node.SecretName
"notes" = ($_.Node.SecretItems.SecretItem | Where-Object { $_.FieldName -eq "Notes" }).Value
"login" = @{
"username" = ($_.Node.SecretItems.SecretItem | Where-Object { $_.FieldName -eq "Username" }).Value
"password" = ($_.Node.SecretItems.SecretItem | Where-Object { $_.FieldName -eq "Password" }).Value
"uris" = @()
}
"fields" = @()
}
# Map "Resource" to URI field if it looks like a URL
[String]$resource = ($_.Node.SecretItems.SecretItem | Where-Object { $_.FieldName -eq "Resource" }).Value
if ($resource) {
if ($resource.StartsWith("http")) {
$item.login.uris += @{
"uri" = $resource
"match" = $null
}
} else {
$item.fields += @{
"name" = "Resource"
"value" = $resource
"type" = 0
}
}
}
$items += $item
}
[PSCustomObject]@{
"folders" = @()
"items" = $items
} | Convertto-Json -Depth 99 | Set-Content -Path $bitwardenImportJSON