要快速获取你PS脚本库中所有文件的函数名,你可以这样做:

复制代码 代码如下:
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脚本中的函数:

复制代码 代码如下:
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    
(...)

将结果用管道传给Out-GridView 将能得到更完美的信息。

支持PS3.0及以后

标签:
Powershell小技巧,查找脚本中的函数

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
内蒙古资源网 Copyright www.nmgbbs.com

评论“Powershell小技巧之查找脚本中的函数”

暂无“Powershell小技巧之查找脚本中的函数”评论...

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。