Search notes:

PowerShell: functions

A function is one of the PowerShell command types which have an entry in the System.Management.Automation.CommandTypes enum.

A function is a script block

A function is basically a named script block:
PS C:\> function dummy() { write-output 42 }
PS C:\> $function:dummy.GetType().FullName
System.Management.Automation.ScriptBlock

All output goes to the pipeline

All output that a function produces goes to the pipeline.
This is fundamentally different from class methods where only values go to the pipeline that are explicitly mentioned with the return statement.

Turning a function into a cmdlet

A function can be turned into a cmdLet by adding [cmdletBinding[()] param() to its declaration. Such a function is said to be advanced:
function do-something {
   [cmdletBinding()]
    param (
      … 
    )
    …
}

Displaying the definition of function

The definition of function might be displayed with the get-content cmdlet:
PS C:\> get-content function:/mkdir

See also

Advanced functions
The .NET classes System.Management.Automation.FunctionInfo and .NET class System.Management.Automation.CmdletBindingAttribute.
The existence of a function can be verified with
PS C:\Users\Rene> test-path function:\mkdir
True
Functions exist in a scope.
Providers
Create a global variable in a function.
A filter is a function that just has the process block.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Windows/...', 1738303051, '18.224.32.56', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Windows/PowerShell/language/function/index(90): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78