Title: Start-Job -InitializationScript should support $using: variable references too · Issue #4530 · PowerShell/PowerShell · GitHub
Open Graph Title: Start-Job -InitializationScript should support $using: variable references too · Issue #4530 · PowerShell/PowerShell
X Title: Start-Job -InitializationScript should support $using: variable references too · Issue #4530 · PowerShell/PowerShell
Description: Note: The bug equally affects Start-ThreadJob. In the script block passed to the (implied as the 1st positional) -ScriptBlock parameter of Start-Job, it is possible to reference variables from the calling scope via the $using: scope; e.g...
Open Graph Description: Note: The bug equally affects Start-ThreadJob. In the script block passed to the (implied as the 1st positional) -ScriptBlock parameter of Start-Job, it is possible to reference variables from the ...
X Description: Note: The bug equally affects Start-ThreadJob. In the script block passed to the (implied as the 1st positional) -ScriptBlock parameter of Start-Job, it is possible to reference variables from the ...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/4530
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Start-Job -InitializationScript should support $using: variable references too","articleBody":"Note: \r\n* The bug equally affects `Start-ThreadJob`.\r\n\r\nIn the script block passed to the (implied as the 1st positional) `-ScriptBlock` parameter of `Start-Job`, it is possible to reference variables from the _calling_ scope via the `$using:` scope; e.g.:\r\n\r\n```powershell\r\n# Make the background job's working directory the same as the calling session's and\r\n# print the then-current location.\r\nStart-Job { Set-Location $using:PWD; $PWD } | Receive-Job -Wait -AutoRemove\r\n```\r\n\r\nBy contrast, the following - even though I'd expect it to be equivalent - does NOT work, because the `$using:` reference is in the `-InitializationScript` script block:\r\n\r\n```powershell\r\nStart-Job -InitializationScript { Set-Location $using:PWD } { $PWD } | Receive-Job -Wait -AutoRemove\r\n```\r\n\r\nInvocation fails with the following error messages:\r\n\r\n```none\r\nA Using variable cannot be retrieved. A Using variable can be used only with \r\nInvoke-Command, Start-Job, or InlineScript in the script workflow. When it is used with\r\nInvoke-Command, the Using variable is valid only if the script block is invoked on\r\na remote computer.\r\n....\r\n```\r\n\r\nNote that the above command would be the cleanest workaround for not having a `-WorkingDirectory` parameter (see #4287) to set the working directory explicitly.\r\n\r\nBoth script blocks execute in the _job_'s session, so they should both support `$using:` variable references.\r\n\r\n\r\nEnvironment data\r\n----------------\r\n\r\n\u003c!-- provide the output of $PSVersionTable -->\r\n\r\n```powershell\r\nPowerShell Core v6.0.0-beta.5 on macOS 10.12.6\r\nPowerShell Core v6.0.0-beta.5 on Ubuntu 16.04.3 LTS\r\nPowerShell Core v6.0.0-beta.5 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)\r\nWindows PowerShell v5.1.15063.483 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2017-08-08T21:37:35Z","url":"https://github.com/PowerShell/PowerShell/issues/4530"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3e72357c-a827-fe2e-0883-38f0482e4367 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 925A:227A70:1125CE:1776AF:6AFD4C31 |
| html-safe-nonce | 8b11fc2dcd18d72365cf890fd9b91b058d2dd63fc47d02923517831b02260210 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MjVBOjIyN0E3MDoxMTI1Q0U6MTc3NkFGOjZBRkQ0QzMxIiwidmlzaXRvcl9pZCI6Ijc4NDg0MDM2OTU5MzIwNzg1NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | cacabb56efc8e580fb12047d663b3baee3e26af2423af39acf5762011cbee0b1 |
| hovercard-subject-tag | issue:248854315 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/4530/issue_layout |
| twitter:image | https://opengraph.githubassets.com/040d2f4799d2ccce5acf4cd87ef58af8bf04bc5c623681c017da158a7e287ad9/PowerShell/PowerShell/issues/4530 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/040d2f4799d2ccce5acf4cd87ef58af8bf04bc5c623681c017da158a7e287ad9/PowerShell/PowerShell/issues/4530 |
| og:image:alt | Note: The bug equally affects Start-ThreadJob. In the script block passed to the (implied as the 1st positional) -ScriptBlock parameter of Start-Job, it is possible to reference variables from the ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width