Command line arguments from unpackaged form

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 10 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
jblomberg
Posts: 7
Last visit: Fri Mar 06, 2015 3:41 pm

Command line arguments from unpackaged form

Post by jblomberg »

Hello, I am trying to pass command line arguments to a powershell form that was created from the new form template in powershell studio. The script has not been packaged. I see from a packaged project you can get the argument from $Commandline variable. Is there a way to get the same command line arguments from a basic unpackaged form? I tried the normal $args[] powershell variable but that does not work.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Command line arguments from unpackaged form

Post by davidc »

Did you define a parameter block at the top of the script?
PowerShell Code
Double-click the code block to select all.
param(
$param1,
$param2
)
David
David
SAPIEN Technologies, Inc.
User avatar
jblomberg
Posts: 7
Last visit: Fri Mar 06, 2015 3:41 pm

Re: Command line arguments from unpackaged form

Post by jblomberg »

I have tried defining in the OnApplicationLoad function without luck.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Command line arguments from unpackaged form

Post by davidc »

It must be place at the top of the script outside of any function. If you are using PowerShell Studio, it will prompt you for parameters if you place it in the correct location.

David
David
SAPIEN Technologies, Inc.
User avatar
jblomberg
Posts: 7
Last visit: Fri Mar 06, 2015 3:41 pm

Re: Command line arguments from unpackaged form

Post by jblomberg »

Sorry, maybe I am doing something wrong but the only way I see to get this at the top of the script is after I export to a powershell file but I don’t see a way to get it to the top of the powershell studio file.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Command line arguments from unpackaged form

Post by davidc »

If you place the parameter block at the top of the editor you will not have to export the file. PowerShell Studio will move it automatically when you export the script.

I've attached a sample form.

David
Attachments
ParameterForm.zip
(1.4 KiB) Downloaded 326 times
David
SAPIEN Technologies, Inc.
User avatar
jblomberg
Posts: 7
Last visit: Fri Mar 06, 2015 3:41 pm

Re: Command line arguments from unpackaged form

Post by jblomberg »

Awesome, that worked, thank you for the help.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Command line arguments from unpackaged form

Post by jvierra »

What confuses some people is that the Parm() starement must br the first statement in the file but not necessarily the first line. YOu will find that it is not at teh top of the exported file but is nestaed in after all of the comments.

Here is an example (scroll down to see Parm statement:

Code: Select all

#------------------------------------------------------------------------
# Source File Information (DO NOT MODIFY)
# Source ID: e360d955-555e-4428-a289-0bd6c1ff1e2e
# Source File: C:\Documents and Settings\jvierra\My Documents\SAPIEN\PowerShell Studio 2012\Files\Demo-Databinding.pff
#------------------------------------------------------------------------
#region File Recovery Data (DO NOT MODIFY)
<#RecoveryData:
hhwAAB+LCAAAAAAABADsvQdgHEmWJSYvbcp7f0r1StfgdKEIgGATJNiQQBDswYjN5pLsHWlHIymr
KoHKZVZlXWYWQMztnbz33nvvvffee++997o7nU4n99//P1xmZAFs9s5K2smeIYCqyB8/fnwfPyIe
v8qn1WVeXz/N2uzoN07S9PGXdXFRLLPyWVHmL7JFfvQ0X1Tb+H5SLGfF8mK8Oj9/fLfXjF/GXz+Z
101RLY92x3uP7/ofCPjJT+fTNm2vV/lnH72+btp8Mf4uAa6umvGzql7Iv6M09tUoVVCf7Y938N8o
PVmX7brOP1vm67bOylH6cj0pi+nvlV+/qd7my88mDx5k96f3P919eG8/3zl4+FG6JGQ/++ic4O1+
lE7nRTmrqd1HJ9Wyrauy+YjRJERf1tUqr9trfeF4Os1X7ZN121ZL04ZavcrPc3p/mmuzCTf48vf6
KL1rAN01kAYgn5RFvmxfFz/IPzq6/2B3lO5/ev/Gl0CPJ1U9y+vX7XVJbz4r3uWzp0VWVhc3vvxF
9q5YUH9Pqnf0YlY2+c2vFMv3fQVc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BE57dD8/delD9nWP7eXzy/HZJPi5qUS1Vf
Uyx4WUxzT6Ruj/LX4c8+YbuY3G4AJ1WdO5zvje/fEucumaePfl9SwxeEYIq8fvP7uuy3U7puOP5Q
qFMzCGBzA96OImISnmRNMfUU9M7PKtmdWojiEcHd/mmMzuOXZL/IxtRmaJ/ny5wQ9KyfNIC5dh/e
jX6qH55NdQ0laBp+SpatOM+b9qTO2ajBv+t9ZlufrBuyfuZ7D/bQFy/LrEVC/2gbfqP5w379ar18
/eYYjoH+5l6sriifP8/L0iwGIcbofWhse0itx6/z6bouyFOwayrhC2l34Ym5o7/4JKjU1Ww9bXuN
O59323cnKvbp07yZ1sUqJPLd6Kcn1WKVLa9pca0pLpaURxHhaNJfmC1Wh6mRb5oKbei9ubqu4XT6
89X/7AwrKLQ+18E7/nF0MU9eGP6KMFs4N1/Q8D95fDdY+DMMC5EgBvHXHf+fAAAA//8uMpeKhhwA
AA==#>
#endregion
#========================================================================
# Code Generated By: SAPIEN Technologies, Inc., PowerShell Studio 2012 v3.1.17
# Generated On: 5/1/2013 4:33 PM
# Generated By: 
# Organization: Designed Systems & Services
#========================================================================
Param($testvar)

The line appears after the end of the recovery block and the generator header but before the header for the generated code. This will pretty much always be the first executable statement.
This topic is 10 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked