which example
# function with one mandatory argument
function Get-FileSize {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$Path
)
if (Test-Path $Path) {
$size = (Get-Item $Path).Length
Write-Output "The size of the file '$Path' is $size bytes."
} else {
Write-Output "The file '$Path' does not exist."
}
}
# worked example
function Which-Command {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string] $CommandName
)
( Get-Command $CommandName ).Path
}
New-Alias -Name which -Value Which-Command