Forum / Remote Desktop Manager - PowerShell Repository

Import Computers from AD

  • Create an Issue
  • Cancel

Simple script to create RDP sessions for every computer on the domain. It simply sets the Name, Host & Description of each computer. If the Description is out of date it will update the field.

cls;

# Query AD
$strCategory = "computer"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = ("(objectCategory=$strCategory)")
$colResults = $objSearcher.FindAll()

# Query RDM
$s = Get-RDM-Session;

foreach ($objResult in $colResults)
{
$objComputer = $objResult.Properties;
$session = $s | Where-Object { $_.name -eq $objComputer.name };

$d = $objComputer.description | Select-Object -first 1;

if (!$session)
{
"New : " + $objComputer.name | echo;
$session = New-RDM-Session -Host $objComputer.name -Kind "RDPConfigured" -Name $objComputer.name;
$session.Description = $d;
Set-RDM-Session -Session $session;
}
else
{
if ($d -and $d -ne $session.Session.Description)
{
"Update : " + $objComputer.name | echo;
Set-RDM-Property -ID $Session.id -Property "Description" -value $d
}
else
{
"Skip : " + $objComputer.name | echo;
}
}
}

Stefane Lavergne

signaturesignature

Clock7 yrs

Hello!

I have a similar script running to add sessions for remote assistance. However, if I try to use the Snchronizer for AD it is much more performant than the script. The synchronizer is able to add 40 sessions in a second where my script needs about 4 seconds for 1 session.

Also if I only try this command it needs about 4 seconds:


Measure-Command {
$session = New-RDM-Session -Name "Name" -Group "RemoteAssistance" -Kind "RemoteAssistance" -TemplateID b507b9f3-991e-4f75-b9b1-d1ff201ab853
Set-RDM-Session $session
}

How can the built-in synchronizer work so fast?

Best regards,
Andy

Clock5 yrs

Good question. The answer is not easy.

We have not fully tested the performance of the PowerShell module so I can't say definitely but there are some things that the PowerShell interface doesn't support. Example: BeginBatch/EndBacth mode supported by some data sources, won't change much in your case since the Server data source doesn't yet support it.

The one thing that will help you in the case is to use either the new commands (New-RDMSession & Set-RDMSession) instead of the deprecated commands (New-RDM-Session & Set-RDM-Session). The new methods do not refresh the UI automatically you must call Update-RDMUI to force the update and you should only do this once at the end of your loop. Your other option if you want to keep using the old commands is to add the -NoRefresh flag to the Set-RDM-Session method call.

This will not get you as fast as the Synchronizer but should be faster than 4 seconds per insert.

Best regards,

Stefane Lavergne

signaturesignature

Clock5 yrs

To add to that

Our AD synchronizer is "pulling" information from AD in well known fields, whereas our Powershell cmdlets (as well as our import CSV wizard) have to "push" information in fields just based on its name. That means that we must match properties by name and this is costly. A push will never be as fast as a pull.



Maurice Côté

signaturesignature

Clock5 yrs

Wow...that boosts my script :-) now it only needs about a half second for one connection. I always thought that I am working with the new commands. Thanks for this tip.

Clock5 yrs

LPT - If the command has two "-" in its name you are using a deprecated command. The new commands follow the PS naming guidelines.

Stefane Lavergne

signaturesignature

Clock5 yrs