Advanced Function

say it: “ad-VANST FUNGK-shun” /ədˈvænst ˈfʌŋkʃən/

A function that behaves like a real cmdlet, with common parameters and pipeline support.

What is Advanced Function?

An advanced function behaves like a real cmdlet: it gets common parameters like -Verbose, validation and pipeline support, thanks to [CmdletBinding()].

function Remove-OldLogs {
    [CmdletBinding()]
    param([int]$Days = 30)
    Write-Verbose "Removing logs older than $Days days"
    Get-ChildItem *.log | Where-Object LastWriteTime -lt (Get-Date).AddDays(-$Days) | Remove-Item
}

Level: Journeyman · More PowerShell terms at this level

Updated