


PowerShell V2 Bug Introduced After Installing V3.PowerShell Debugging: You can change variables but don’t shoot yourself in the foot!.Debugging PowerShell modules with PrimalScript.

Debugging multiple scripts with PrimalScript.Most GUIs will run fine in MTA mode, but as a general rule, we recommended that you always run your GUI scripts in STA mode.ĭavid Corrales is Senior Software Engineer at SAPIEN Technologies, Inc. STA mode is not something you normally have to consider when writing scripts, but it is something that you should be aware of if you are creating GUIs tools. To determine whether a Windows PowerShell host program is running in STA mode, use this command to check the value of the ApartmentState property: $host. Windows PowerShell ISE always runs in STA mode. If you are using Windows PowerShell 2.0, use the following command to start Windows PowerShell with the STA option: Starting in Windows PowerShell 3.0, the Windows PowerShell console runs in STA mode by default. If you add the following comment to your script, PowerShell Studio and PrimalScript run the script in STA mode: # %ForceSTA% = True Next, make sure that your Windows PowerShell scripts require STA when running. But, when you package a script, be sure to retain the STA mode settings.Ĭlick Deploy and in the Packager section, click Settings and then Engine Settings. Luckily, PowerShell Studio detects when your form includes an STA mode dependent control and runs it in STA mode. For example: :: SetText( "Paste this text to the clipboard" ) Packaging and STA mode: Form with TopMost property set to True.Īlso, static methods of the Clipboard class require STA mode.DataGridView with Ctrl + C to copy text in cells.The following control features require STA mode. If you’re interested in the details, see Processes, Threads, and Apartmen ts in the Microsoft Developer Center. I will not go into the detail, but you need not concern yourself with the inner workings of COM objects, other than to remember that STA is required for some of the GUI controls to function correctly. STA (Single Threaded Apartment) and MTA (Multi-Threaded Apartment) determine how a process manages legacy COM objects and their communication with multiple threads.

Recently, on our forums, a user asked why certain controls didn’t function correctly or threw an error when he unchecked the STA option in PowerShell Studio.
