Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Powershell在SSIS包中查找存储过程_Powershell_Ssis_Full Text Search_Text Search - Fatal编程技术网

使用Powershell在SSIS包中查找存储过程

使用Powershell在SSIS包中查找存储过程,powershell,ssis,full-text-search,text-search,Powershell,Ssis,Full Text Search,Text Search,我正在尝试使用PowerShell搜索目录中的所有SSI包,并返回以下内容: 文件的路径和名称 包含存储过程名称的行,即“exec mystoredproc” 我想用来搜索的条件只是“exec”,或者如果可能的话是“exec或execute”,我希望exec后面字符串末尾的空格作为返回的分隔符 我试过: Get-ChildItem -recurse | Select-String -pattern "exec" | group path | select name 但是,这只返回文件名,而

我正在尝试使用PowerShell搜索目录中的所有SSI包,并返回以下内容:

  • 文件的路径和名称
  • 包含存储过程名称的行,即“exec mystoredproc”
我想用来搜索的条件只是“exec”,或者如果可能的话是“exec或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

似乎为我要查找的命令提供了正确的文件和行号。是否有某种方法可以打印行号引用的行而不是编号?我已经查看了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)

这是返回Execute和命令的字母(Execute p、Execute a等)。我正在寻找执行下一个单词直到空间。可以将字符串模式修改为这种效果吗?而且,它似乎只找到了“execute”,但我知道“exec”也存在。@Jake,哎呀,这是我的正则表达式中的一个错误。我想我现在已经改正了。好多了,谢谢!还有一个请求-有没有办法让每个命令显示在不同的行上(路径和名称也在每行上重印)?@Jake这只是一个对象,所以你可以做任何你想做的事情:
foreach($item in(Get StoredProcedure)){$item.command;$item.Path+'+$item.Name}