上QQ阅读APP看书,第一时间看更新
Functions
Functions are similar to cmdlets and should follow the same naming conventions. Whereas cmdlets are compiled units of PowerShell functionality written in managed code like C#, functions are written using the PowerShell language. Starting with PowerShell 2.0, it has been possible to write advanced functions, which are very similar to cmdlets. It is possible to use common parameters and risk mitigation parameters with advanced functions. An example of a function is shown as follows:
function get-PowerShellVersionMessage{
param($name)
$PowerShellVersion=$PSVersionTable.PSVersion
return "We're using $PowerShellVersion, $name!"
}
Calling the function at the command line is straightforward, as shown in the following screenshot: