Powershell小技巧之查找腳本中的函數(shù)
要快速獲取你PS腳本庫中所有文件的函數(shù)名,你可以這樣做:
filter Find-Function
{
$path = $_.FullName
$lastwrite = $_.LastWriteTime
$text = Get-Content -Path $path
if ($text.Length -gt 0)
{
$token = $null
$errors = $null
$ast = [System.Management.Automation.Language.Parser]::ParseInput($text, [ref] $token, [ref] $errors)
$ast.FindAll({ $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] }, $true) |
Select-Object -Property Name, Path, LastWriteTime |
ForEach-Object {
$_.Path = $path
$_.LastWriteTime = $lastwrite
$_
}
}
}
這將掃描出你用戶配置文件夾下的所有PS腳本中的函數(shù):
PS> dir $home -Filter *.ps1 -Recurse -Exclude *.ps1xml | Find-Function
Name Path LastWriteTime
---- ---- -------------
Inject-LogonCredentials C:\Users\Tobias\Desktop... 06.01.2014 02:43:00
Test-Command C:\Users\Tobias\Desktop... 06.03.2014 10:17:02
Test C:\Users\Tobias\Desktop... 30.01.2014 09:32:20
Get-WebPictureOriginal C:\Users\Tobias\Desktop... 11.12.2013 11:37:53
Get-ConnectionString C:\Users\Tobias\Documen... 23.05.2014 10:49:09
Convert-SID2User C:\Users\Tobias\Documen... 23.05.2014 15:33:06
Lock-Screen C:\Users\Tobias\Documen... 19.03.2014 12:51:54
Show-OpenFileDialog C:\Users\Tobias\Documen... 16.05.2014 13:42:16
Show-UniversalData C:\Users\Tobias\Documen... 16.05.2014 13:23:20
Start-TimebombMemory C:\Users\Tobias\Documen... 23.05.2014 09:12:28
Stop-TimebombMemory C:\Users\Tobias\Documen... 23.05.2014 09:12:28
(...)
將結(jié)果用管道傳給Out-GridView 將能得到更完美的信息。
支持PS3.0及以后
相關(guān)文章
PowerShell計(jì)算腳本執(zhí)行時(shí)間的實(shí)現(xiàn)方法
如果你想知道一個(gè)腳本運(yùn)行了多久時(shí)間,你可以使用Measure-Command,但是這個(gè)命令僅用于診斷目的且沒有輸出2014-04-04PowerShell重啟服務(wù)命令Restart-Service詳細(xì)介紹
這篇文章主要介紹了PowerShell重啟服務(wù)命令Restart-Service詳細(xì)介紹,Restart-Service命令主要用來重啟一些系統(tǒng)級(jí)的服務(wù),需要的朋友可以參考下2014-08-08Powershell直接腳本時(shí)出現(xiàn)無法加載文件因?yàn)榻箞?zhí)行腳本
Powershell直接腳本時(shí)出現(xiàn)無法加載文件因?yàn)樵诖讼到y(tǒng)中禁止執(zhí)行腳本,有關(guān)此問題的解決方法如下2014-08-08Powershell小技巧之使用-F方法帶入數(shù)據(jù)
這篇文章主要介紹了Powershell的一個(gè)使用-F方法帶入數(shù)據(jù)的小技巧,非常的簡(jiǎn)單,也很易懂,記錄一下分享給大家2014-09-09linux下非阻塞模式網(wǎng)絡(luò)通訊模型示例分享
這篇文章主要介紹了linux下非阻塞模式網(wǎng)絡(luò)通訊模型示例,需要的朋友可以參考下2014-02-02PowerShell腳本trap語句捕獲異常寫法實(shí)例
這篇文章主要介紹了PowerShell腳本trap語句捕獲異常寫法實(shí)例,包含幾個(gè)代碼實(shí)例,需要的朋友可以參考下2014-07-07PowerShell入門教程之快速學(xué)習(xí)PowerShell的幾個(gè)方法
這篇文章主要介紹了PowerShell入門教程之快速學(xué)習(xí)PowerShell的幾個(gè)方法,本文提出了3種快速學(xué)習(xí)PowerShell的方法,需要的朋友可以參考下2014-10-10添加powershell腳本來解決nuget打包文件丟失問題
這里給大家分享的是作者在使用nuget打包的過程中遇到丟失文件的問題的時(shí)候使用powershell腳本實(shí)現(xiàn)的解決辦法,非常的巧妙,這里推薦給大家2017-11-11PowerShell中使用.NET將程序集加入全局程序集緩存
這篇文章主要介紹了PowerShell中使用.NET將程序集加入全局程序集緩存,本文介紹了兩種方法實(shí)現(xiàn)把程序集加入全局程序集緩存,著重講解了使用.Net的類庫解決這個(gè)需求,需要的朋友可以參考下2015-06-06PowerShell使用正則表達(dá)式查找字符串實(shí)例
這篇文章主要介紹了PowerShell使用正則表達(dá)式查找字符串實(shí)例,主要是對(duì)match運(yùn)算符的使用介紹,需要的朋友可以參考下2014-08-08