我使用自定义PowerShell函数来让我的生活更轻松.
例:
# custom function
> function build {cmd /c build.ps1}
# invoke the function
> build
Run Code Online (Sandbox Code Playgroud)
这很好,可以让我快速运行我的构建脚本.
不可思议的是,很容易忘记我创建的所有自定义函数.
是否有一个cmdlet可以运行以转储我的自定义函数列表?随后,一旦我知道这些函数是什么,是否有一个cmdlet可以运行以删除我不再需要的函数?
Cha*_*ell 25
获取可用功能列表
> Get-ChildItem function:\
Run Code Online (Sandbox Code Playgroud)
删除powershell函数
# removes `someFunction`
> Remove-Item function:\someFunction
Run Code Online (Sandbox Code Playgroud)
将此添加到您的个人资料:
$sysfunctions = gci function:
function myfunctions {gci function: | where {$sysfunctions -notcontains $_} }
Run Code Online (Sandbox Code Playgroud)
和myfunctions将仅列出自会话开始以来创建的函数.
我不喜欢给出的答案,因为出于某种原因,当我打电话时,我没有从我的个人资料中看到我的自定义函数,Get-ChildItem function:所以这是我所做的:
Function Get-MyCommands {
Get-Content -Path $profile | Select-String -Pattern "^function.+" | ForEach-Object {
# Find function names that contains letters, numbers and dashes
[Regex]::Matches($_, "^function ([a-z0-9.-]+)","IgnoreCase").Groups[1].Value
} | Where-Object { $_ -ine "prompt" } | Sort-Object
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23240 次 |
| 最近记录: |