June 13, 2011

Calling Macro Scheduler Functions from PowerShell

Filed under: General,Scripting — Marcus Tettmar @ 11:34 am

Further to my post about the MacroScript SDK the other day, here’s an example of loading the MacroScript SDK COM object from PowerShell and running some Macro Scheduler code:

  $objMS = new-object -comobject "mscript.macroscript"
  $objMS.Init()
  $objMS.RunCode( "Run>notepad.exe" + [Environment]::NewLine + 
  		"WaitWindowOpen>Untitled - Notepad" + [Environment]::NewLine + 
  		"Wait>0.5" + [Environment]::NewLine + 
  		"Send>Hello World", "")
  $objMS.Cleanup()

You will need to put the mscript.dll file into the system path (e.g. System32/SysWow64) or into the PowerShell folder.

Don’t forget that with the MacroScript SDK you can retrieve information and query the data back to PowerShell using the GetVar function (see previous post). So for all you system administrators using PowerShell but needing the GUI automation capabilities of Macro Scheduler as well, the MacroScript SDK is the perfect companion.