Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 

PowerShell Studio is full of features and options. As a new user, I’m trying to learn as many as I can. There are four options in the Run menu, so, of course, I tried them all. But the result was unexpected.

 

options in the Run Menu

 

Run and Run Selection run your code and show the result in the Output pane. Run in Console and Run Selection in Console run your code and show the result in the Console pane, which is a separate Windows PowerShell process that PowerShell Studio hosts. That’s expected.

 

But Run Selection and Run Selection in Console are very different from each other.

  • Run Selection runs each selection in a separate Windows PowerShell session. It’s as though you opened a PowerShell window, ran some commands, displayed the results, and immediately closed the window. If you use Run Selection to run a few more commands, you just opened a new window with a new session that is unaware of the previous session.
  • Run Selection in Console uses the same Windows PowerShell session for all commands. You might have heard this called a “persistent runspace.” When you run a series of Run Selection in Console commands, all of the commands run in the same session and they’re aware of each other. If you create a session-specific object, such as a variable, it’s available to all selections that you run.

 

To test the difference, run the following commands as separate selections, first by using Run Selection and then by using Run Selection in Console.

  • $a = “Try the zip cmdlets (-Archive) in Windows PowerShell 5.0 Preview”
  • $a

 

If you use Run Selection, the result of the final “$a” statement is $null, because the assignment statement ran in a different session.

Run Selection Output

 

But if you use Run Selection in Console, the result is:

Run Selection in Console Output

 

If you need a new Windows PowerShell session in the Console pane, type exit or right-click and click Restart Shell. (If you type powershell, you get a nested session, just like you would in the Windows PowerShell console. To return to the original session, type quit.)

right-click then restart shell

 

Now that I understand these features, I can use PowerShell Studio more adeptly. And, what about those Archive cmdlets? I’ll save that treat for another article!

June Blender is a technology evangelist at SAPIEN Technologies, Inc. You can reach her at This email address is being protected from spambots. You need JavaScript enabled to view it. and follow her on Twitter at @juneb_get_help.

If you have questions about our products, please post in our support forum.
For licensed customers, use the forum associated with your product in our Product Support Forums for Registered Customers.
For users of trial versions, please post in our Former and Future Customers - Questions forum.
Copyright © 2024 SAPIEN Technologies, Inc.