The Function provider provides access to the functions defined in Windows PowerShell. By using the function provider you can obtain a listing of all the functions on your system. You can also add, modify, and delete functions. The function provider uses a file system–based model, and the cmdlets learned earlier also apply to working with functions. The commands used in the procedure are in the ListingAllFunctionsOnTheSystem.txt file.
Open Windows PowerShell.
Use the Set-Location cmdlet to change the working location to the function PSDrive. This command is shown here:
Set-Location function:\
Use the Get-ChildItem cmdlet to enumerate all the functions. Do this by using the gci alias, as shown here:
GCI
The resulting list contains many functions that use Set-Location to the different drive letters. A partial view of this output is shown here:
CommandType Name Definition ----------- ---- ---------- Function prompt 'PS ' + $(Get-Location) + $(... Function TabExpansion ... Function Clear-Host $spaceType = [System.Managem... Function more param([string[]]$paths); if... Function help param([string]$Name,[string[... Function man param([string]$Name,[string[... Function mkdir param([string[]]$paths); New... Function md param([string[]]$paths); New... Function A: Set-Location A: Function B: Set-Location B: Function C: Set-Location C: Function D: Set-Location D:
To return only the functions that are used for drives, use the Get-ChildItem cmdlet and pipe the object returned into a Where-Object cmdlet. Use the default $_ variable to filter on the definition attribute. Use the like argument to search for definitions that contain the word set. The resulting command is shown here:
GCI | Where {$_.definition -like "set*"}
If you are more interested in functions that are not related to drive mappings, then you can use the notlike argument instead of like. The easiest way to make this change is to use the up arrow and retrieve the gci | where {$_.definition -like "set*"} and then change the filter from like to notlike. The resulting command is shown here:
GCI | Where {$_.definition -notlike "set*"}
The resulting listing of functions is shown here:
CommandType Name Definition ----------- ---- ---------- Function prompt 'PS' + $(Get-Location) + $(... Function TabExpansion ... Function Clear-Host $spaceType = [System.Managem... Function more param([string[]]$paths); if... Function help param([string]$Name,[string[... Function man param([string]$Name,[string[... Function mkdir param([string[]]$paths); New... Function md param([string[]]$paths); New... Function pro notepad $profile
Use the Get-Content cmdlet to retrieve the text of the md function. This is shown here:
Get-Content md
The content of the md function is shown here:
param([string[]]$paths); New-Item -type directory -path $paths
This concludes this procedure.