powershell - 使用 Powershell 查找 SSIS 包中的存储过程
问题描述
我正在尝试使用 PowerShell 搜索目录中的所有 SSIS 包,并返回以下内容:
- 文件的路径和名称
- 包含存储过程名称的行,即“exec mystoredproc”
我想用来搜索的标准只是“exec”,或者“exec or execute”(如果可能),我希望 exec 后面的字符串末尾的空格作为返回的分隔符.
我试过了:
Get-ChildItem -recurse | Select-String -pattern "exec" | group path | select name
但是,这仅返回文件名,而不是所需的附加文本。
如果有比 PowerShell 更好的方法来做到这一点,我愿意接受,但根据我目前发现的情况,这似乎是正确的道路。先感谢您!
编辑: 继续研究,我发现这个命令
Get-ChildItem -recurse | Select-String -pattern exec,execute | Select filename,linenumber
似乎为我正在寻找的命令提供了正确的文件和行号。有没有办法让 linenumber 引用的行打印而不是数字?我查看了 ForEach 和 Get-Content,但似乎无法完全正确地理解语法。
解决方案
这是一个应该证明对您有用的功能:
function Get-StoredProcedure {
[CmdletBinding()]
[OutputType('System.Management.Automation.PSObject')]
param(
[Parameter(Position = 0, ValueFromPipeline)]
[System.IO.FileInfo[]] $Path = (Get-ChildItem -Recurse -File)
)
process {
foreach ($item in $Path) {
[pscustomobject]@{
'Path' = Split-Path -Parent -Path $item.FullName
'Name' = $item.Name
'Command' = ($item | Select-String -Pattern 'exec(ute)?\s[^\s]+').Matches.Value
}
}
}
}
这将遍历FileInfo
您传递给它的任何对象(请注意使用-File
或Get-ChildItem
过滤掉该PSIsContainer
属性)。它以字符串的形式返回一个对象,其中包含路径、文件名和命令exec(ute) <contiguous non-spaces>
推荐阅读
- react-native - react native run android 卡在“在 android 上打开...”
- python - 如何在函数更改其参数类型时编写 Python 类型提示
- xamarin - 关于 Xamarin 和 Net 5 的一些疑问
- python - 使用python将字典日志文件转换为csv
- c++ - 声明变量使 OpenGL 窗口关闭
- javascript - 在 Vue 方法中使用函数
- google-cloud-automl - 自动完成时 AutoML 中的验证集中没有足够的图像
- powershell - psCustomObject 作为返回的数据,奇怪的管道错误
- optaplanner - Optaplanner:添加动态访问而不更改已创建的访问
- python - 如何将路径参数转发到 VPC 链路端点?