How to Use Powershell Scripts in Ubot Studio 

 July 19, 2021

By  Reed

Powershell gives you extensive control over your computer. With it you can turn on and off internet connections, check to see if a bot is running, and access thousands of modules like Autoit to control the window of running programs. The benefits of powershell is that it is on every Windows machine and comes with a helpful editing tool Powershell IDE that lets you test run your scripts.

Why Use Powershell?

One of the hardest parts of coding is remembering how to use a command, but powershell makes it easy because it comes with a tool that helps you correctly use the commands available to your powershell install. In some ways powershell is easier to use than Python!

If you can think of something missing in Ubot then try searching for it in powershell. Chances are it can be done. An example of a powershell command I’ve personally used and vouch for is Invoke-WebRequest. It lets you visit and download webpages without having to launch a browser. You can hit a site and download it for later. It’s a great way to capture a site and automate it without having to hit it repeatedly, which is what the pros do. With it you can also do GET and POST requests which you can use to call and interact with API’s without a browser.

Another great module is Autoit. Autoit is an excellent automation tool that is mostly designed for IT professionals but has many bot builders using it to automate games and programs. Autoit itself has a ton of addon libraries available that basically extend the tool, but it is an extensive scripting language and even with it’s extensive help documentation it can be a bit of a rabbit hole. It’s worth looking at and using to automate a computer and some software windows. It has a great image recognition library for finding and clicking on images, and makes it easy to send keystrokes to a software window. With it you can automate many things you cannot in Ubot. 

Use The Shell Command

To use powershell scripts in Ubot, we use the Shell command. The shell command is a quick way to launch .exe’s. When we enter the full path to a programs .exe and run the Shell command we can open that program.  What some do not know is that the Shell command can also take parameters. Parameters are little addons that tell the program to do something when it opens. Parameters are available for most programs, in fact the browser you are using has many parameters available. For example you can have your browser open to a webpage by entering the path to the browsers .exe with the websites domain at the end. It looks like this:


So, rather than having to launch the browser THEN navigate to it we can have it launched with it. Parameters are an easy way to speed up your productivity.

shell("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe C:\\Users\\pain4\\OneDrive\\Desktop\\Listings\\powershell-autoit-test.ps1")

Powershell works the same way, but with a filepath. You set the parameter to be the filepath of the .ps1 powershell script. The shell script looks like this:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\Users\pain4\OneDrive\Desktop\Listings\powershell-autoit-test.ps1

It is the path to the powershell.exe and the file path to the powershell script we want to run. Naturally, you would write the script in Powershell IDE, test run it by hitting f5 (same as test running in Ubot), and then run it with the Shell command in Ubot. It’s best practice to know it works before running it in Ubot.


Use The Powershell Plugin

Aymen has been on the Ubot forum for over a decade. He has put in the time and become an absolute ASSET to the Ubot community. Without him we wouldn’t have access to the essential plugins he has released over the years. One of his most recent plugins is definitely one of his simplest with only 1 function $powerShell execute. With it you don’t have to run an existing .ps1 powershell script, you can simply paste the script into the $powerShell execute function and run it directly in Ubot.

The first example uses Autoit’s powershell module to open notepad and return the title of the window. The second example does the same but also types text and then fetches the documents text and returns it.

load html($plugin function("UbotPowerShell.dll", "$powerShell execute", "Invoke-AU3Run -Program notepad.exe
$notepadTitle = \"Untitled - Notepad\"
Wait-AU3Win -Title $notepadTitle
$winHandle = Get-AU3WinHandle -Title $notepadTitle
return $notepadTitle"))
load html($plugin function("UbotPowerShell.dll", "$powerShell execute", "Invoke-AU3Run -Program notepad.exe
$notepadTitle = \"Untitled - Notepad\"
Wait-AU3Win -Title $notepadTitle
$winHandle = Get-AU3WinHandle -Title $notepadTitle
Show-AU3WinActivate -WinHandle $winHandle
$controlHandle = Get-AU3ControlHandle -WinHandle $winhandle -Control \"Edit1\"
Set-AU3ControlText -ControlHandle $controlHandle -NewText \"Hello! This is being controlled by AutoIt and PowerShell!\" -WinHandle $winHandle
Send-AU3ControlKey -ControlHandle $controlHandle -Key \"\{ENTER\}simulate key strokes - line 1\" -WinHandle $winHandle
Send-AU3ControlKey -ControlHandle $controlHandle -Key \"\{ENTER\}\" -WinHandle $winHandle
$text = Get-AU3ControlText -Title \"*Untitled - Notepad\" -Control \"Edit1\"
return $text"))

In both cases we are RETURN’ing something because that’s how the plugin works. Something has to be returned. This is how you can retrieve data from a powershell script to use in Ubot.

Resources Mentioned


Warning: Invalid argument supplied for foreach() in /home/actionreed/public_html/su/wp-content/themes/thrive-theme/inc/classes/class-thrive-theme-comments.php on line 463

Your email address will not be published. Required fields are marked

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Subscribe to our newsletter now!

Follow by Email

Forgot Password?

Join Us