Skip to content

Commit 81ffaf4

Browse files
committed
first attempt at a function to replace xml part of a platform
1 parent 8422ab0 commit 81ffaf4

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

Update-PASPlatformFiles.ps1

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Update-PASPlatformFiles {
2525
if ($File.Name -eq (Get-ChildItem $CPMPolicyFile).Name) {
2626
Add-PVFile -safe PasswordManagerShared -folder root\Policies -file $File.Name -localFolder $File.DirectoryName -localFile $File.Name
2727
} elseif ($File.Name -eq (Get-ChildItem $PVWASettingsFile).Name) {
28-
# Do something some day? Download Policies.xml, replace what is in Policies.xml with what is in PVWASettingsFile, then upload?
28+
Update-PoliciesXml -PVWASettingsFile $PVWASettingsFile -PlatformId $PlatformId
2929
} else {
3030
Add-PVFile -safe PasswordManagerShared -folder root\ImportedPlatforms\Policy-$PlatformId -file $File.Name -localFolder $File.DirectoryName -localFile $File.Name
3131
}
@@ -37,4 +37,34 @@ function Update-PASPlatformFiles {
3737
Disconnect-PVVault
3838
Stop-PVPacli
3939
}
40+
}
41+
42+
function Update-PoliciesXml {
43+
param (
44+
$PVWASettingsFile,
45+
$PlatformId
46+
)
47+
48+
$TemporaryFile = New-TemporaryFile
49+
50+
Open-PVSafe -safe PVWAConfig
51+
Get-PVFile -safe PVWAConfig -folder root -file Policies.xml -localFolder $TemporaryFile.DirectoryName -localFile $TemporaryFile.Name
52+
53+
$PoliciesXml = [xml](Get-Content $TemporaryFile)
54+
$PVWASettingsXml = [xml](Get-Content $PVWASettingsFile)
55+
56+
# Search via PlatformId as it could be a Policy, Usage, whatever.
57+
$ExistingPolicyElement = $PoliciesXml.SelectNodes("//*[@ID='$PlatformId']")
58+
# Import the Policy element from the PVWASettingsFile to the PoliciesXml document.
59+
$NewPolicyElement = $PoliciesXml.ImportNode($PVWASettingsXml.SelectSingleNode("//*[@ID='$PlatformId']"))
60+
61+
# Add the new policy element we imported, replace the old one.
62+
# Can this be done better with .ReplaceChild()?
63+
$ExistingPolicyElement.ParentNode.AppendChild($NewPolicyElement)
64+
$ExistingPolicyElement.ParentNode.RemoveChild($ExistingPolicyElement)
65+
66+
$PoliciesXml.Save($TemporaryFile.FullName)
67+
68+
Add-PVFile -safe PVWAConfig -folder root -file 'Policies.xml' -localFolder $TemporaryFile.DirectoryName -localFile $TemporaryFile.Name
69+
Close-PVSafe -safe PVWAConfig
4070
}

0 commit comments

Comments
 (0)