Attempting to convert Terminals (Robert Chartier) favorites file to mRemoteNG config file. Both files are XML. I need to loop through the favorites file that looks like this (C:TemptempTerminals.xml):
<?xml version="1.0" encoding="utf-8"?>
<favorites>
<favorite>
<protocol>RDP</protocol>
<port>3389</port>
<serverName>first.machine.local</serverName>
<url>rdp://first.machine.local:3389/</url>
<name>First Machine</name>
<notes />
<tags>FM</tags>
<newWindow>False</newWindow>
<toolBarIcon />
<bitmapPeristence>RDP</bitmapPeristence>
<credential />
<domainName />
<desktopSize>AutoScale</desktopSize>
<desktopSizeHeight>600</desktopSizeHeight>
<desktopSizeWidth>800</desktopSizeWidth>
<colors>Bit16</colors>
<sounds>DontPlay</sounds>
<redirectClipboard>True</redirectClipboard>
<enableTLSAuthentication>True</enableTLSAuthentication>
<enableNLAAuthentication>True</enableNLAAuthentication>
<idleTimeout>240</idleTimeout>
<overallTimeout>600</overallTimeout>
<connectionTimeout>600</connectionTimeout>
<shutdownTimeout>10</shutdownTimeout>
</favorite>
</favorites>
And I need to add each of them to an empty mRemoteNG config file that looks like this (C:TemptempRemoteng.xml):
<?xml version="1.0" encoding="utf-8"?>
<mrng:Connections xmlns:mrng="http://mremoteng.org" Name="Connections" Export="false"
EncryptionEngine="AES" BlockCipherMode="GCM" KdfIterations="1000"
FullFileEncryption="false" Protected="<A really long value>" ConfVersion="2.6">
< New nodes are to go here >
</mrng:Connections>
This is what each child node should look like:
<Node Name="<Name from favorite>" Type="Connection" Descr="" Icon="mRemoteNG"
Panel="General" Id="<Need new GUID here>" Username="_username_" Domain="_domain_"
Password="_password" Hostname="<serverName from favorite>" Protocol="RDP"
PuttySession="Default Settings" Port="3389" ConnectToConsole="false"
UseCredSsp="true" RenderingEngine="IE" ICAEncryptionStrength="EncrBasic"
RDPAuthenticationLevel="NoAuth" RDPMinutesToIdleTimeout="0" />
(There’s actually a lot more attributes, I just truncated it for example)
I need to modify the Name, Hostname attributes and add a new GUID in the Id attribute.
This code, gives me the error “The specified node cannot be inserted as the valid child of this node, because the specified node is the wrong type.”
$terminals = Get-Content -Path "C:TemptempTerminals.xml"
$terminalsDoc = [xml]$terminals
$remoteNg = Get-Content -Path "C:TemptempRemoteng.xml"
$remoteNgDoc = [xml]$remoteNg
clear
# Accessing elements
$root = $terminalsDoc.favorites.ChildNodes
$childNode = $remoteNgDoc.ChildNodes[1]
foreach($node in $root)
{
$rootValue = $node.name
$rootURI = $node.serverName
$newNode = [xml]@"
<Node Name="$($rootValue)" Type="Connection" Descr="" Icon="mRemoteNG" Panel="General" Id="$(New-Guid)" Username="_username_" Domain="_domain_" Password="_Password_"
Hostname="$($rootURI)" Protocol="RDP" PuttySession="Default Settings" Port="3389" ConnectToConsole="false" UseCredSsp="true" RenderingEngine="IE" ICAEncryptionStrength="EncrBasic" RDPAuthenticationLevel="NoAuth" RDPMinutesToIdleTimeout="0" />
"@
$childNode.AppendChild($newNode)
}
Just having difficulty understanding handling of XML in PowerShell.
BTW, I tried using Import-CliXml on both files and am getting this error:
Import-CliXml : Element 'Objs' with namespace name 'http://schemas.microsoft.com/powershell/2004/04' was not found. Line 1, position 2.