Converting scripts into functions
A function is a reusable, callable code block(s). A function can accept parameters and can produce different results.
A typical anatomy of a PowerShell function looks like this:
function Do-Something { <# comment based help #> param ( #parameters ) #blocks of code }
To illustrate, let's create a very simple function that takes a report server URL and lists all items in that report server.
Note
When naming functions, it is recommended that you adhere to the verb-noun convention. The verb also needs to be approved; otherwise, you may get a warning similar to when you import the SQLPS
module:
WARNING: The names of some imported commands from the 'sqlps'
module include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module
command again with the verbose parameter. For a list of approved verbs, type Get-Verb
.
This function will take in a parameter for the report...