Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass needed parameters to script in Powershell ISE?

See Title.

I specified needed parameters in the head of a script:

param ($G_ARCHIVE = $(throw "Need file to upload!"),        $G_LOGFILE = $(throw "Need logfile!")) 

When I want to debug the script with Powershell ISE: how can I fill these parameters?

like image 455
eckes Avatar asked Jan 14 '11 10:01

eckes


People also ask

How do you pass parameters in PowerShell script?

A default value will not work with a mandatory parameter. You can omit the =$true for advanced parameters of type boolean [Parameter(Mandatory)] . @Andrew First of all you have to change the type of the parameter to [string] . If you then want to pass a string as parameter you can use either ' or " .

How do I pass multiple parameters to a PowerShell script?

To pass multiple parameters you must use the command line syntax that includes the names of the parameters. For example, here is a sample PowerShell script that runs the Get-Service function with two parameters. The parameters are the name of the service(s) and the name of the Computer.

How do you make a parameter required in PowerShell?

To make a parameter mandatory add a "Mandatory=$true" to the parameter description. To make a parameter optional just leave the "Mandatory" statement out. Make sure the "param" statement is the first one (except for comments and blank lines) in either the script or the function.

What is param () in PowerShell?

A parameter doesn't have to be a placeholder for a variable. PowerShell has a concept called parameter attributes and parameter validation. Parameter attributes change the behavior of the parameter in a lot of different ways. For example, one of the most common parameter attributes you'll set is the Mandatory keyword.


1 Answers

Use the command pane. Open the script file in the ISE editor, set the breakpoints (F9). Then in the command pane type a command invoking this script with required parameters. I do not think there is another (built-in) way of doing this in ISE.

like image 121
Roman Kuzmin Avatar answered Oct 06 '22 02:10

Roman Kuzmin