How to stress test terminal services with Windows Powershell

When you want to do scalability testing for your terminal services (or Remote Desktop Services on Windows Server 2008 R2) you need some automation to make this easier. There is Remote Desktop Load Simulation Tool that you can use to test your environment. I tried to use this in one of my customers recently and had to … enhance it to fit my needs.

Briefly the tool is using a COM API (RemoteUIControl.dll) to connect through the Remote Desktop protocol to send necessary commands and you can use a script to simulate user activity. You would need to install 3 sets of tools on 3 different parts to do the testing. Please be aware that the method I am about to tell is not supported or endorsed by Microsoft. Instead of using the tool components provided I decided to use the API to create my own test tools. You need RemoteUIControl.dll and RUIDCOM.exe on your test clients. You will need TSAccSessionAgent.exe running on your terminal servers. You can simply get the client components installed on your tester client and Server components installed on RDS servers.

Now to start the testing you would require users, lots of them. (Image the movie Matrix, where Neo tells “We need guns lots of them”). You can simply run a Windows Powershell script to create test users. Here is a simple loop to do this on your Windows Server 2008 R2 DC (Note that you will need the modules to be loaded to use New-ADuser cmdlet to function):

for ($i=1;$i -le  $NumberOfusers;$i++)



$Password = ConvertTo-SecureString "12345678" -AsPlainText –Force

$DN="CN=" + $CN + "," +$TargetOU

New-ADUser $CN -Path $TargetOU  -AccountPassword $password -Enabled $True


Of course you would need to set the variables for your environment. After this is done, you will want to create a script that will run as a test user to create activity. I am leaving this as an exercise as there is pretty good vbscript example inside the tool I mentioned above.

The next step will be to replicate those testers to create a simultaneously acting users to create load on your remote Desktop services. Here is a loop to do this. Please keep in mind that you do not need to run this on your DC and not even in the same script that is used to create users:

for ($i=1;$i -le  $NumberOfusers;$i++)




Start-process -FilePath "c:\windows\system32\cscript.exe" -ArgumentList $ArgList

sleep -seconds 1


When you first run this script you will see several (depending on number of users) windows pop up and they will connect to your remote desktop the first time and new profiles will be created. This is a very intensive operation and if your numbers of users are high, will easily choke your server(s). That is the reason to have a sleep statement to slow this down. Some of the users may not be able to connect or finish the script that you provide. The next run will be much easier.

Finally if some of your connections are hanged you will need to terminate the processes on your client machine. This can be easily done by the following command:

get-process -name ruidcom | foreach-object {$_.kill()}

This is a very powerful command and should be used with caution. If you do not provide the name of the process, it will kill all the processes on your client which will instantly turn off your machine 🙂

Comments (3)
  1. It is a  script to provide actions on Remote Desktop sessions. Example script is provided in Remote Desktop load simulation tool provided at…/details.aspx

  2. sarah says:

    What is test2.vbs?

  3. Hsafla says:

    At the end of the script can you have any exit state ? Because I want to use this method to "monitor" user experience on RDS server. So i want to know if the test.vbs is finiished in a good state.

Comments are closed.

Skip to main content