Vscode-powershell: Passing Arguments to vscode-powershell

Created on 18 Jul 2017  ·  6Comments  ·  Source: PowerShell/vscode-powershell

System Details

  • Operating system name and version:
  • VS Code version:
  • PowerShell extension version:
  • Output from $PSVersionTable:
Copy / paste the below commands into the PowerShell Integrated Terminal, and paste the output here

code -v
$pseditor.EditorServicesVersion
code --list-extensions --show-versions
$PSVersionTable

Issue Description

Another stupid question. How do I pass in arguments when running Powershell code in VS code Powershell editor?

Attached Logs

Follow the instructions in the README
about capturing and sending logs.

Most helpful comment

Have a look at:

https://blogs.technet.microsoft.com/heyscriptingguy/2017/02/06/debugging-powershell-script-in-visual-studio-code-part-1/
https://blogs.technet.microsoft.com/heyscriptingguy/2017/02/13/debugging-powershell-script-in-visual-studio-code-part-2/

Specifically part 2, section "Launch configuration settings / variables".

You can also add a new Debug Configuration (open your .vscode/launch.json file and press the Add Config button) called "PowerShell: Launch Current File w/Args". This configuration will prompt you for the arguments.

All 6 comments

Have a look at:

https://blogs.technet.microsoft.com/heyscriptingguy/2017/02/06/debugging-powershell-script-in-visual-studio-code-part-1/
https://blogs.technet.microsoft.com/heyscriptingguy/2017/02/13/debugging-powershell-script-in-visual-studio-code-part-2/

Specifically part 2, section "Launch configuration settings / variables".

You can also add a new Debug Configuration (open your .vscode/launch.json file and press the Add Config button) called "PowerShell: Launch Current File w/Args". This configuration will prompt you for the arguments.

Does this look right?

I just want to pass a string “qa” as argument zero.

The top portion of my launch.json file

{
"version": "0.2.0",
"configurations": [
{
"type": "PowerShell",
"request": "launch",
"name": "PowerShell Launch Current File w/Args Prompt",
"script": "${file}",
"args": ["-myArg qa"],
"cwd": "${file}"

-Joe B.

From: Keith Hill [mailto:[email protected]]
Sent: Tuesday, July 18, 2017 11:09 AM
To: PowerShell/vscode-powershell vscode-powershell@noreply.github.com
Cc: Bruns, Joe W. (TR Technology & Ops) joe.bruns@thomsonreuters.com; Author author@noreply.github.com
Subject: Re: [PowerShell/vscode-powershell] Passing Arguments to vscode-powershell (#965)

Have a look at:

https://blogs.technet.microsoft.com/heyscriptingguy/2017/02/06/debugging-powershell-script-in-visual-studio-code-part-1/https://urldefense.proofpoint.com/v2/url?u=https-3A__blogs.technet.microsoft.com_heyscriptingguy_2017_02_06_debugging-2Dpowershell-2Dscript-2Din-2Dvisual-2Dstudio-2Dcode-2Dpart-2D1_&d=DwMFaQ&c=4ZIZThykDLcoWk-GVjSLmy8-1Cr1I4FWIvbLFebwKgY&r=EmXB1hdqAUsNr2oNinCjmF_WQrDx6UdLKFBtFym2pdM&m=ekZk3Dtyi3Dziv6pkoeoD9niLZ6jxUvMZ-vBAaaI1Nc&s=CqPS2mufuJJe90FBBL5jHDtLxaPOUGzUgB6sxoS789c&e=
https://blogs.technet.microsoft.com/heyscriptingguy/2017/02/13/debugging-powershell-script-in-visual-studio-code-part-2/https://urldefense.proofpoint.com/v2/url?u=https-3A__blogs.technet.microsoft.com_heyscriptingguy_2017_02_13_debugging-2Dpowershell-2Dscript-2Din-2Dvisual-2Dstudio-2Dcode-2Dpart-2D2_&d=DwMFaQ&c=4ZIZThykDLcoWk-GVjSLmy8-1Cr1I4FWIvbLFebwKgY&r=EmXB1hdqAUsNr2oNinCjmF_WQrDx6UdLKFBtFym2pdM&m=ekZk3Dtyi3Dziv6pkoeoD9niLZ6jxUvMZ-vBAaaI1Nc&s=GUnYYPGLoE7OjIdCGi48wvz9sCJB9h-SPFST5ZBV-Gw&e=

Specifically part 2, section "Launch configuration settings / variables". You can also add a new Debug Configuration (open your .vscode/launch.json file and press the Add Config button) called "PowerShell: Launch Current File w/Args". This configuration will prompt you for the arguments.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHubhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_PowerShell_vscode-2Dpowershell_issues_965-23issuecomment-2D316113999&d=DwMFaQ&c=4ZIZThykDLcoWk-GVjSLmy8-1Cr1I4FWIvbLFebwKgY&r=EmXB1hdqAUsNr2oNinCjmF_WQrDx6UdLKFBtFym2pdM&m=ekZk3Dtyi3Dziv6pkoeoD9niLZ6jxUvMZ-vBAaaI1Nc&s=0uRv6vL31teUuX3CoqBDmjdt_SFPHbx5fcCzzItHFAk&e=, or mute the threadhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AObZjCoOfvMyLLbenBTJPSNPD-5FfXHuuCks5sPNiPgaJpZM4Objpa&d=DwMFaQ&c=4ZIZThykDLcoWk-GVjSLmy8-1Cr1I4FWIvbLFebwKgY&r=EmXB1hdqAUsNr2oNinCjmF_WQrDx6UdLKFBtFym2pdM&m=ekZk3Dtyi3Dziv6pkoeoD9niLZ6jxUvMZ-vBAaaI1Nc&s=JFp_NJY4bvEzeSYz6ZLTwZ78FbzvziK70VAc1-Rwy2Q&e=.

If you want VSCode to prompt you for the args, set your args to:

"args": [ "${command:SpecifyScriptArgs}" ]

If you want to specify the args directly in the launch.json, what you have should work. Just make sure the file you want to debug is in the active editor window when you press F5.

My issue was I was opening ps1 directly with VS Code which suppresses the gear icon, confusing the hell out of me.

[cid:[email protected]]

-Joe B.

From: Keith Hill [mailto:[email protected]]
Sent: Tuesday, July 18, 2017 12:56 PM
To: PowerShell/vscode-powershell vscode-powershell@noreply.github.com
Cc: Bruns, Joe W. (TR Technology & Ops) joe.bruns@thomsonreuters.com; Author author@noreply.github.com
Subject: Re: [PowerShell/vscode-powershell] Passing Arguments to vscode-powershell (#965)

If you want VSCode to prompt you for the args, make your set your args to:

"args": [ "${command:SpecifyScriptArgs}" ]

If you want to specify the args directly in the launch.json, what you have should work. Just make sure the file you want to debug is in the active editor window when you press F5.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHubhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_PowerShell_vscode-2Dpowershell_issues_965-23issuecomment-2D316144722&d=DwMFaQ&c=4ZIZThykDLcoWk-GVjSLmy8-1Cr1I4FWIvbLFebwKgY&r=EmXB1hdqAUsNr2oNinCjmF_WQrDx6UdLKFBtFym2pdM&m=djqw9MdJV39mJC9jW-ryGiGSA3a0O6Sv8V9MIxYVSGc&s=_EOjVVDX_sRnYprQrBf45KMmMyTZbx7Lg-H4CJ0OIQ4&e=, or mute the threadhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AObZjNwwYwWr39r8IRStrrn-2DgODhABD1ks5sPPGxgaJpZM4Objpa&d=DwMFaQ&c=4ZIZThykDLcoWk-GVjSLmy8-1Cr1I4FWIvbLFebwKgY&r=EmXB1hdqAUsNr2oNinCjmF_WQrDx6UdLKFBtFym2pdM&m=djqw9MdJV39mJC9jW-ryGiGSA3a0O6Sv8V9MIxYVSGc&s=JREb7PnEvRzql78P58Z4KMItp6ZbzQpXLE_J1iXjsm4&e=.

Glad you got it working.

@jbruns2015 Can you please share with me how you resolved this issue?
I'm having trouble understanding where should I put this launch.json file, and also if this workd olny in debug mode or also in "Run Code" mode..
Plz contact me at: [email protected] or respond here.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

itfranck picture itfranck  ·  3Comments

MiYanni picture MiYanni  ·  3Comments

timoline picture timoline  ·  3Comments

pcgeek86 picture pcgeek86  ·  4Comments

guidooliveira picture guidooliveira  ·  3Comments