Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.

IDM Designer - Removing disabled rules with PowerShell

IDM Designer - Removing disabled rules with PowerShell

Description


We inherited an environment with a lot of policy rules marked as disabled in the Policy Builder within IDM Designer. Within these rules there are also nested disabled conditions and actions, which in order to be seen need to be expanded in the GUI. We wanted to find a way to remove these rules without going through the tedious task of expanding hundreds of rules.


Solution


We created a PowerShell script that iterates through every .xml file and looks for the specified XPath expression and delete all nodes that matches the expression.

The files are saved in the in the OEM encoding type which takes the default encoding for MS-DOS, in our case ANSI. Different -Encoding values can be found on Microsoft docs here.

Do note that IDM Designer does not seem to like any other encoding than ANSI for the xml files.

$ErrorActionPreference = "stop"
Set-Location $PSScriptRoot
$counter = 0
# Iterate through all files that are .xml
$files = Get-ChildItem '.' -Recurse *.xml | ? {
Test-Path $_.FullName -PathType Leaf
$xml = New-Object -TypeName XML
# Load the file
try {
$xml.Load($_.FullName)
}
catch{}
$selector = $null
try {
# Collect all nodes
$selector = Select-XML -Xml $xml -XPath '//*[@disabled="true"]'
if ($selector -ne $null)
{
# If they exist, iterate through them and remove
Foreach($item in $selector)
{
Write-Host $_.FullName
# Remove the node
$null = $item.Node.ParentNode.RemoveChild($item.node)
$counter++
}
# Save the file
# Probably possible to combine the three lines below, right now we're saving twice.
$xml.Save($_.FullName)
$content = Get-Content $_.FullName
$content | Out-File $_.FullName -Encoding OEM
}
}
catch {$_.Exception.message}
}
Write-Host $counter "occurences of disabled='true' found"




After usage and import of the project again the disabled rules are removed:



Usage



Perform a backup of your Designer project: Right Click your Project > Copy Project

Save the script as <scriptname>.ps1 and place it at the root of your project backup directory and run it with CMD:

powershell .\<scriptname>.ps1

Windows might complain about running scripts depending on which execution policy is set. The execution policy can be changed to a less restrictive one with:
powershell Set-ExecutionPolicy <execution policy value>.


Execution policy values can be found here.

More information about Set-ExecutionPolicy can be found here.

When the script is finished the backup project can be imported, verify that the disabled rules are removed.

Versions



NetIQ Designer 4.7

PowerShell
C:\Windows\system32> powershell $PSVersionTable.PSVersion

Major Minor Build Revision
----- ----- ----- --------
5 1 17134 590

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2019-03-22 20:38
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.