Just a tip #3 – $args in PowerShell

In scripting, there are many things to experience in many ways, the traditional way is always the best practice though, the formal way is always an option…

Traditional way


Function Add
{
param
(
[Parameter(Mandatory=$true)]
<span></span>[int] $Number1,
[Parameter(Mandatory=$true)]
[int] $Number2
)
[int] $Sum = 0
$Sum = $Number1 + $Number2
return, $Sum
}

Add -Number1 4 -Number2 5

Add tip 1

Formal way


<span></span>$Add = {$args[0] + $args[1]}
. $Add 4 5

Add tip 2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s