Link to home
Start Free TrialLog in
Avatar of Kelly Garcia
Kelly GarciaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Calling a function

HI All,

What's the best way to call a function,

is it:

function CreateVM()
	{
	
	}


$VMName = "ENV-WEB"
CreateVM($VMName)

Open in new window


or

function CreateVM($VMName)
	{
	
	}

$VMName = "ENV-WEB"
CreateVM env-web

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh and... by convention, when developing functions it is worth trying to stick to the development guidelines. Functions are commands, and commands should use verb-noun pairing, with a verb from the list of well-known verbs (Get-Verb).

Development guidelines: https://msdn.microsoft.com/en-us/library/ms714657(v=vs.85).aspx
Approved verbs: https://msdn.microsoft.com/en-us/library/ms714428(v=vs.85).aspx
Style guide: https://github.com/PoshCode/PowerShellPracticeAndStyle

The value of these practices and guidelines comes when it becomes clear that other people might end up working on the code you're producing. You can only do so much, but if a script or module ignores established practices it's that much harder to adjust in the future.

For me the rule is simple, I can name things as a please when I'm tapping away for my own purposes, but anything I produce for other people must adhere to a reasonable set of styling rules.

This is a bit of a development rabbit hole, but if you spend a lot of your day writing code you are a developer.
Avatar of Kelly Garcia

ASKER

thanks Chris, really appreciate it.

my function is linked to a button, i want to call the function only once upon pressing the button once the processing is complete then they can select another button, how do i do this?

thank you in advance,
Kelly
Put the function call into the event attached to the button (in the same manner as you would have to open a window). You can force progress through the GUI by enabling and disabling elements as you move between steps.