Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ASG-RD PowerShell Module issue
#1
Hi,

I need some advice regarding the PowerShell Module.

I need the change the "Destination (the connection)" on some Virtual Machines using the PowerShell Module.
However, I cannot retrieve all the "childpaths" by using the module, and therefore not get all the virtual machine that runs in the child folders.
Imagine this structure.

Folder1
- folder 2
  - folder 3
     - vm1
     - vm2

-folder 4
 -vm 2

I need to get all the VM's ind the Folder1 (and in the subfolders aswell). How to I achieve this?

Thanks in advance!

Lha
Reply
#2
The Powershell command is "Get-RDBaseItemChilds -ParentItemId <ID>" - optional you can specify if only connections or folders should be returned

Then you only need to put it in a foreach statement and you should be able to perform your task by using "Set-RDPropertiesConnection" - all commands are explained in chapter Powershell of the online help
Regards/Gruss
Oliver
Reply
#3
(13-08-2020, 01:16 PM)DevOma Wrote: The Powershell command is  "Get-RDBaseItemChilds -ParentItemId <ID>" - optional you can specify if only connections or folders should be returned

Then you only need to put it in a foreach statement and you should be able to perform your task by using "Set-RDPropertiesConnection" - all commands are explained in chapter Powershell of the online help

Hi DevOma

I know this is an old thread but I'm stuck at the same thing.

The command "Get-RDBaseItemChilds -ParentItemId <ID>" only shows folders / connections / etc. directly below the parentitem.
In other words, the search is not recursive.

I got a folder-structure with different depths and I want to get all connections inside a top-level directory (the connections are in different subfolders of this top-level dir).
As far as ive seen, there is no way to accomplish this.
I hope I am wrong as I really need a way to do this.
Reply
#4
I'm not a Powershell expert - so I could not give you the right statements out of the box - but I think it is easy to find the commands on any "powershell example script" website

You always have an entry point - a folder - and the ID of this folder! Then you need a function like

GetChildElements - you call this function with the ID of the folder - in the function get all childs - add the child connections to a list object - and call the GetChildElements function again for all child folders - then this will go through all subfolders and add all connections from all subfolders to your list


We will add a new parameter -recursive to support this function directly out of the box for the next version!
Regards/Gruss
Oliver
Reply
#5
Code:
function get-folder_rekursiv($ParentID)
{
    $tmp_rekursivlist = @()
    $tmp_child_all = Get-RDBaseItemChilds -ParentItemId $ParentID -ItemType Folder
    if($tmp_child_all -eq $null)
    {
        #do nothing
    }
    else
    {
        foreach($tmp_child_single in $tmp_child_all)
        {
            $tmp_child_single_id = $tmp_child_single.ItemId.Guid
            $tmp_rekursivlist += $tmp_child_single_id
            $tmp_subfunction = get-folder_rekursiv($tmp_child_single_id)
            foreach($subtotop in $tmp_subfunction)
            {
                if($tmp_rekursivlist -notcontains $subtotop)
                {
                    $tmp_rekursivlist += $subtotop
                }
            }
        }
    }
    return $tmp_rekursivlist
}

Hi,
this is my solution from a previous work where i tried to archive something similar.
However i needed to make a recurse search by myself and maybe that helps you too.

This Skript gives you pack a complete list of all folders that are under any given Root/Start Folder
Reply
#6
Wink 
(07-06-2021, 04:14 PM)Nachtschatten Wrote:
Code:
function get-folder_rekursiv($ParentID)
{
    $tmp_rekursivlist = @()
    $tmp_child_all = Get-RDBaseItemChilds -ParentItemId $ParentID -ItemType Folder
    if($tmp_child_all -eq $null)
    {
        #do nothing
    }
    else
    {
        foreach($tmp_child_single in $tmp_child_all)
        {
            $tmp_child_single_id = $tmp_child_single.ItemId.Guid
            $tmp_rekursivlist += $tmp_child_single_id
            $tmp_subfunction = get-folder_rekursiv($tmp_child_single_id)
            foreach($subtotop in $tmp_subfunction)
            {
                if($tmp_rekursivlist -notcontains $subtotop)
                {
                    $tmp_rekursivlist += $subtotop
                }
            }
        }
    }
    return $tmp_rekursivlist
}

Hi,
this is my solution from a previous work where i tried to archive something similar.
However i needed to make a recurse search by myself and maybe that helps you too.

This Skript gives you pack a complete list of all folders that are under any given Root/Start Folder

Thanks, this works perfectly.
I was looping through 20+ foreachs in my script, this is a lot smoother :-)
Reply




Users browsing this thread: 1 Guest(s)