Sunday, 15 January 2012

scope - How do I use a variable from one session (a Powershell ISE tab) in another? -


Here's a barebones code of what I'm trying to achieve ..

  $ DestinationDir = "subdir1" #creating tab $ newtab = $ psise.PowerShellTabs.Add () Do {sleep-m 100} While $rbin.Invoke ($ CD $ destinationDir) required script #running in the tab (! $ NewTab.CanInvoke) })  

Since the $ destinationDir parent does not start in the tab, it is limited to its scope and I

  the CD Kids tab The following error gets in: can not be process logic because The value of Rk "path" Change tap-tap assume the value of zero argument "path".  

How can I remove it and use the value in the hair tab?

Brief answer: You can not make each tab in PowerShell ISE built with a new runspace. There is no method available for injection of the variable in this runspace.

Long answer: There are always workmen. I have two here.

Use the invocation script block to transfer 1 new runpace variable:

  $ destinationDir = "subdir1" #creating tab $ newtab = $ Psise.PowerShellTabs.Add () do {sleep -m 100} while $ ($ $ newTab.CanInvoke) $ scriptblock = "` $ destinationDir = `" $ ($ destinationDir) `'in the CD $$ destinationDir" Running essential script $ newTab.Invoke ($ scriptblock)  

Use 2 environment variable EN:

  $ env: DestinationDir = "subdir1" #creating tab $ newtab = $ psise.PowerShellTabs.Add () Do {sleep-m 100} while $ ($ $ NEWTab.CanInvoke) tab $ newTab.Invoke ({CD $ env: destinationDir} in #running Need A script)  

No comments:

Post a Comment