PS C:\>

Unleash your script

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework.

Use MahApps.metro built-in dialogs

Apply beautiful modal dialog into your project.

How to apply a theme on your GUI?

Some tips on how to apply a theme on your GUI ...

Showing posts with label Console. Show all posts
Showing posts with label Console. Show all posts

Sunday, 9 July 2017

How to pass arguments to a powershell script?

It’s been a while folks. Recently, a colleague of mine asked me how to pass argument(s) to a PowerShell script and how does it work. I even come across the same problem when I started PowerShell so I decided to write something about it for those who may need.

Let’s dig into the subject:
Basically, you want to achieve something like this:

.\Powershell.exe “C:\myScript.ps1” -args1 “value1” -args2 “value2” […]  -optional1 -optional2 […]

With as many arguments and optional switch you want.

How it is done?


Edit your script and at the head of your file before everything add the following lines:


The statement:

Param(): declares parameters that will be used, pretty obvious.
[Parameter()]: specifications about the parameter if it is mandatory, its position …
[string] /[int] /[switch]: parameters type.

Share:

Popular Posts

Join us on Facebook

STATS

Contact Form

Name

Email *

Message *

image
Hello,

Thank you for visiting my blog and reading this far.

I'm mainly focusing on scripting, software development and modern workpalce experiences with Microsoft Technology. I created this blog for the main purpose of sharing my knowledge. Hope you will appreciate my works and will help you in yours. You are friendly invited to leave any kind of feedback in the comment sections of my posts.

Please note that all posts on this blog are my own opinions and are provided "as is", without warranty of any kind.