0

I am trying to create an RDCMan file (.rdg xml file) using PowerShell. I have started by defining this template

$newFileTemplate = '<?xml version="1.0" encoding="utf-8"?>
<RDCMan programVersion="2.7" schemaVersion="3">
    <file>       
    <properties>
        <expanded>False</expanded>
        <name>Office Servers</name>
    </properties>    
    <displaySettings inherit="None">
        <liveThumbnailUpdates>True</liveThumbnailUpdates>
        <allowThumbnailSessionInteraction>False</allowThumbnailSessionInteraction>
        <showDisconnectedThumbnails>True</showDisconnectedThumbnails>
        <thumbnailScale>1</thumbnailScale>
        <smartSizeDockedWindows>True</smartSizeDockedWindows>
        <smartSizeUndockedWindows>False</smartSizeUndockedWindows>
    </displaySettings>
    </file>
</RDCMan>
'

before creating an xml object like so

$File = 'D:\Test.rdg'
Set-Content $File $newFileTemplate
[XML]$XMLFile = [XML](Get-Content $File)

I would then like to define a function for adding a group of servers

# This function adds a new group element
Function Add-NewGroup($GroupName,$RDCManFile) {
    [xml]$GroupXML = @"
    <group>
      <properties>
        <expanded>False</expanded>
        <name>$GroupName</name>
      </properties>
    </group>
"@
    $Child = $RDCManFile.ImportNode($GroupXML.group, $true)
    $RDCManFile.Configuration.AppendChild($Child)
}

And call it by running

Add-NewGroup('DCs',$XMLFile)

This would allow me to populate the xml file with all of the OUs in AD. Is anyone able to tell me where I am going wrong?

Thanks

Update: The error I am getting is

You cannot call a method on a null-valued expression.
At D:\Users\user\Desktop\Projects\RDCMan\Create-RDG.ps1:179 char:5
+     $Child = $RDCManFile.ImportNode($GroupXML.group, $true)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At D:\Users\user\Desktop\Projects\RDCMan\Create-RDG.ps1:180 char:5
+     $RDCManFile.Configuration.AppendChild($Child)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

And I am trying to do what was suggested here https://stackoverflow.com/a/29693625/2165019

2
  • What kind of output are you receiving? Are you getting errors? It's hard to say where you're going wrong if we don't know what is wrong. Commented Jun 11, 2020 at 18:14
  • Hi @AutomatedOrder thanks for having a look at this. I have updated the description for you. Commented Jun 12, 2020 at 7:59

3 Answers 3

0
  1. The property 'Configuration' cannot be found on this object. Verify that the property exists. error at $RDCManFile.Configuration.AppendChild($Child).

If I can accept a .rdg file format and structure as defined in the Script to create a Remote Desktop Connection Manager group from Active Directory Technet article then I'd use

$RDCManFile.RDCMan.file.AppendChild($Child)
  1. Follow the Theo's answer about calling a function.

Pass parameters as positional

Add-NewGroup 'DCs' $XMLFile

or as named

Add-NewGroup -GroupName 'DCs' -RDCManFile $XMLFile
Sign up to request clarification or add additional context in comments.

1 Comment

Hi JosefZ thank you so much for your suggestions! I can confirm that the script is now working for me.
0

This error (and second) most likely means that $RDCManFile is null.

You cannot call a method on a null-valued expression.
At D:\Users\user\Desktop\Projects\RDCMan\Create-RDG.ps1:179 char:5
+     $Child = $RDCManFile.ImportNode($GroupXML.group, $true)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Try adding $RDCManFile | Out-Host at the top of the Add-NewGroup function to check what's contained in that variable.

1 Comment

Hi Cbsch it looks like the problem was related to me calling the function wrong. Thanks for the help.
0

You need to change the way you are calling the function.

Because of the comma in between the parameters, PowerShell sees this as one array value, so only parameter $GroupName will receive something.

Furthermore, you should not use brackets around the params, call the function like this:

Add-NewGroup 'DCs' $XMLFile

or send the parameters using their names:

Add-NewGroup -GroupName 'DCs' -RDCManFile $XMLFile

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.