Jump to content

Using the AutoIt PowerShell Cmdlets

Recommended Posts


This is a quick start guide to using the AutoIt PowerShell Cmdlets. The best bits of AutoIt directly from PowerShell :) 

The files you need are as follows (get them from the zip file or the Program Files folder after installation):

  • AutoItX.psd1
  • AutoItX3.PowerShell.dll
  • AutoItX3.Assembly.dll
  • AutoItX3.dll
  • AutoItX3_x64.dll

To use the Cmdlets open a PowerShell cmd prompt and enter:

Import-Module .\AutoItX.psd1


Now you can get a list of available AutoIt Cmdlets by doing Get-Command *AU3*:

PS> Get-Command *AU3*

Name                              Category  Module 
----                              --------  ------ 
Invoke-AU3MouseWheel              Cmdlet    AutoItX
Move-AU3Mouse                     Cmdlet    AutoItX
Invoke-AU3MouseClickDrag          Cmdlet    AutoItX
Get-AU3MouseCursor                Cmdlet    AutoItX
Invoke-AU3MouseUp                 Cmdlet    AutoItX
Assert-AU3WinActive               Cmdlet    AutoItX
Assert-AU3WinExists               Cmdlet    AutoItX
Assert-AU3IsAdmin                 Cmdlet    AutoItX
Invoke-AU3Shutdown                Cmdlet    AutoItX
Send-AU3ControlKey                Cmdlet    AutoItX
Invoke-AU3MouseDown               Cmdlet    AutoItX
Invoke-AU3MouseClick              Cmdlet    AutoItX
Invoke-AU3ControlTreeView         Cmdlet    AutoItX
Invoke-AU3ControlListView         Cmdlet    AutoItX
Invoke-AU3ControlCommand          Cmdlet    AutoItX
Invoke-AU3ControlClick            Cmdlet    AutoItX
Move-AU3Control                   Cmdlet    AutoItX
Set-AU3ControlText                Cmdlet    AutoItX
Show-AU3Control                   Cmdlet    AutoItX
Hide-AU3Control                   Cmdlet    AutoItX
Get-AU3ControlText                Cmdlet    AutoItX
Get-AU3ControlFocus               Cmdlet    AutoItX
Set-AU3ControlFocus               Cmdlet    AutoItX
Disable-AU3Control                Cmdlet    AutoItX
Enable-AU3Control                 Cmdlet    AutoItX
Get-AU3StatusbarText              Cmdlet    AutoItX
Invoke-AU3RunAsWait               Cmdlet    AutoItX
Invoke-AU3RunAs                   Cmdlet    AutoItX
Invoke-AU3RunWait                 Cmdlet    AutoItX
Invoke-AU3Run                     Cmdlet    AutoItX
Set-AU3Clip                       Cmdlet    AutoItX
Get-AU3Clip                       Cmdlet    AutoItX
Set-AU3WinTrans                   Cmdlet    AutoItX
Set-AU3WinTitle                   Cmdlet    AutoItX
Set-AU3WinState                   Cmdlet    AutoItX
Set-AU3WinOnTop                   Cmdlet    AutoItX
Move-AU3Win                       Cmdlet    AutoItX
Show-AU3WinMinimizeAllUndo        Cmdlet    AutoItX
Show-AU3WinMinimizeAll            Cmdlet    AutoItX
Get-AU3WinState                   Cmdlet    AutoItX
Get-AU3WinProcess                 Cmdlet    AutoItX
Get-AU3WinClassList               Cmdlet    AutoItX
Get-AU3WinCaretPos                Cmdlet    AutoItX
Get-AU3WinClientSize              Cmdlet    AutoItX
Get-AU3ControlPos                 Cmdlet    AutoItX
Get-AU3ControlHandle              Cmdlet    AutoItX
Get-AU3MousePos                   Cmdlet    AutoItX
Get-AU3WinPos                     Cmdlet    AutoItX
Get-AU3WinHandle                  Cmdlet    AutoItX
Get-AU3ErrorCode                  Cmdlet    AutoItX
Initialize-AU3                    Cmdlet    AutoItX
Show-AU3WinActivate               Cmdlet    AutoItX
Close-AU3Win                      Cmdlet    AutoItX
Wait-AU3WinClose                  Cmdlet    AutoItX
Wait-AU3WinNotActive              Cmdlet    AutoItX
Set-AU3Option                     Cmdlet    AutoItX
Send-AU3Key                       Cmdlet    AutoItX
Wait-AU3Win                       Cmdlet    AutoItX
Wait-AU3WinActive                 Cmdlet    AutoItX
Get-AU3WinTitle                   Cmdlet    AutoItX
Get-AU3WinText                    Cmdlet    AutoItX


I’ll show how to use the Cmdlets using a simple example that will open notepad.exe and modify the edit window by setting the text and simulating some keystrokes. First create a blank PowerShell script called notepad_example.ps1 in the same folder as the AutoItX components above and open it for editing.

Now we want to import the PowerShell module which is AutoItX.psd1. Enter the following in the script:

Import-Module .\AutoItX.psd1


We want to run notepad.exe:

Invoke-AU3Run -Program notepad.exe


After notepad opens we want to wait for the notepad “Untitled -Notepad” window to appear. You might need to change the title for non-English versions of Windows:

$notepadTitle = "Untitled - Notepad"
Wait-AU3Win -Title $notepadTitle
$winHandle = Get-AU3WinHandle -Title $notepadTitle


Get-AU3WinHandle returns a native Win32 handle to the notepad window. We can use this handle in many other AutoIt functions and it uniquely identifies the window which is much more reliable than constantly using a windows title. If you have obtained a window handle using any other Win32 function you can use it with AutoIt.

After obtaining the handle to the notepad window we want to ensure that the window is active and then get a handle to the Edit Control. Using the AU3Info.exe tool that comes with AutoIt we can find that the name of the edit control in notepad is Edit1.

Show-AU3WinActivate -WinHandle $winHandle
$controlHandle = Get-AU3ControlHandle -WinHandle $winhandle -Control "Edit1"


Now that we have a handle to the edit control we can set text in two ways: Directly (Set-AU3Controltext) or with simulated keystrokes (Send-AU3ControlKey):

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

Now let’s see what the entire script looks like:

# Import the AutoIt PowerShell module
Import-Module .\AutoItX.psd1

# Run notepad.exe
Invoke-AU3Run -Program notepad.exe

# Wait for an untitled notepad window and get the handle
$notepadTitle = "Untitled - Notepad"
Wait-AU3Win -Title $notepadTitle
$winHandle = Get-AU3WinHandle -Title $notepadTitle

# Activate the window
Show-AU3WinActivate -WinHandle $winHandle

# Get the handle of the notepad text control for reliable operations
$controlHandle = Get-AU3ControlHandle -WinHandle $winhandle -Control "Edit1"

# Change the edit control
Set-AU3ControlText -ControlHandle $controlHandle -NewText "Hello! This is being controlled by AutoIt and PowerShell!" -WinHandle $winHandle

# Send some keystrokes to the edit control
Send-AU3ControlKey -ControlHandle $controlHandle -Key "{ENTER}simulate key strokes - line 1" -WinHandle $winHandle
Send-AU3ControlKey -ControlHandle $controlHandle -Key "{ENTER}simulate key strokes - line 2" -WinHandle $winHandle
Send-AU3ControlKey -ControlHandle $controlHandle -Key "{ENTER}{ENTER}" -WinHandle $winHandle


This is how the notepad window should look if everything is working correctly:


Share this post

Link to post
Share on other sites

Please add this to AutoItX HelpFile.


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-31

Share this post

Link to post
Share on other sites

Could we have examples for each commandlets in autoitx.

Example : get-help autoit-commandlet -full 

If that provides examples it would really help to incorporate faster.could not find any other resources in internet also. 

Edited by PrakashVel
Needed to complete the message info.

Share this post

Link to post
Share on other sites
On 11/29/2015 at 11:58 AM, PrakashVel said:

Could we have examples for each commandlets in autoitx.

Example : get-help autoit-commandlet -full 

If that provides examples it would really help to incorporate faster.could not find any other resources in internet also. 

Agreed.  The environment in which I work pretty much classifies any AutoIT script I write as a virus and quarantines it immediately, forcing me to use powershell.  Initially I thought I was just stupid (and/or lazy for disregarding the trial/error approach) for having difficulty in determining the autoit function that each powershell function was related to :P, but seeing as I am not the first to request that information be included with the module, I feel less stupid.  Please do include at least the autoit function that corresponds to the given powershell function in the autoit powershell module.  That would be greeeaaaattttt.

Share this post

Link to post
Share on other sites

Sorry, for bringing this up in this post, but I have a issue with this exampel.

n00b question

Maybe you can help me?

Yours sincerely


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • PramodR
      By PramodR
      I see couple of ways to import module ,  one with specifying absolute path of the file to get imported, by this logic i believe to import a specific module will be like #include <c:\modulepath\duplicatemodule.au3>
      but i see some registry changes also made in this link , can someone explain why that registry change is really required.
    • PramodR
      By PramodR
      I am trying to execute a exe file in auto it as elevated previlage , but not successful till now . below are the methods i tried till now.
      Disabled UAC access from windows and  selected run only as administrator from executable properties.  i logged in as administrator but still exe needs to launch as run as administrator.
      Used Below methods from forum still no luck. anything i missing? i tried to use powershell.ps1 intead of exe as well.
      1.  Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, $RUN_LOGON_NOPROFILE, "c:\Exec.exe", "", @SW_SHOWMAXIMIZED)
      2.  RunWait("C:\Automation\TestScripts\Writefilter.exe", @WindowsDir, @SW_MAXIMIZE)     - Std out error
      This command gives out put as running with admin rights
      #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #RequireAdmin Example() Func Example()     ; Change the username and password to the appropriate values for your system.     Local $sUserName = "Admin"     Local $sPassword = "PASSWORD"     Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, 0, "noetpad.exe", "", @SW_SHOWMAXIMIZED)     ; Run Notepad with the window maximized. Notepad is run under the user previously specified. ;~     RunWait(@WindowsDir & "C:\automation\TestScripts\Writefilter.exe", @WindowsDir, @SW_MAXIMIZE) EndFunc   
    • PramodR
      By PramodR
      I have below code which execute well when all prerequisite met, when window pop up is not available its throwing an error. i want to capture error instead of error  out.
      error handling added in the code to capture it but it does not work still giving me error saying Variable must be of type "Object".
      $oCurWin.FindAll($treescope_subtree, $oCondition, $pElements)
      $oCurWin^ ERROR
      How to catch error properly . 
    • PramodR
      By PramodR
      I have to execute below block of code in elevated previllage, as that particular wmic class will work only with admin previlage.
      i am getting out put when i launch autoit as administrator,  but i will not be able to launch autoit as admin in this particular case but my user have admin rights.
      is there any better way i can run those command as administrator.?
      tried below steps:
      i have tried #RequireAdmin but that creates a user prompt  Tried using Runas command but gives error as wrong username or password , stuck with that step.  
    • IgImAx
      By IgImAx
      UPDATED Notes: ===============================================================================
      UPDATED: My main and second questions answered. Here the answers:
      To add/access WinMenuSelectItem you need to [Thanks to Fernando_Marinho]: Add AutoItX.Dotnet in Manage NuGet Packages Right Click in your Project -> Add -> Reference... -> COM ( Type Libraries )than, check the option AutoItX3 1.0 Type Library  using AutoItX3Lib; AutoItX3 au3 = new AutoItX3(); au3.WinMenuSelectItem("", ...) My full source code in C# exists in 11 posts in below. How to access those overloaded methods in AutoitX3 that are not accessible via above method!? Or how to fix AutoitX3 DLL Registration need in target computers without Autoit pre-installed on them!? Please check my post at 14 posts below!
      =============================================================================== Original Post:
      I was writing a small app in Autoit to close µTorrent app. It was working. Then I try to import AutoItX into C#, but unfortunately this method
      WinMenuSelectItem Couldn't find by IntelliSense and If I typed completely it still give me this message:
      Please check the image. I Google it and I found this QA at stackoverflow: Autoit error within C# application I saw they use this line:
      au = new AutoItX3Lib.AutoItX3Class(); I figure it how to add 'AutoItX3Lib' to project (by adding 'AutoItX3.dll' to reference) but again! When I use this line:
      var au = new AutoItX3Class(); I got this error message: Interop type 'AutoItX3Class' cannot be embedded. Use the applicable interface instead.
      My system info:
      Visual Studio 2017 Enterprise - v15.5.4
      X64 Windows 10 Enterprise 1607
      Thanks in advanced