Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

Converting VBScript's Sub Statement

Windows PowerShell

Definition: Declares the name, arguments, and code that form the body of a Sub procedure.


Windows PowerShell supports only functions, as opposed to functions and subroutines. You can define a function in Windows PowerShell by using the function statement followed by:

  • The name of the function.

  • The task to be performed by the function (enclosed in curly braces).

For example, the following command defines a function named MultiplyNumbers. This function will take two arguments ($args[0] and $args[1]) and then multiply those two values. Here’s the command:

function multiplynumbers { $args[0] * $args[1] }

From then on you can call the function simply by specifying the function name and the two values you want multiplied:

multiplynumbers 38 99

When you run the preceding command you should get back the following:


Return to the VBScript to Windows PowerShell home page

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft