Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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
Sql server powershell正则表达式错误,DBCC发出警告除外_Sql Server_Regex_Powershell_Regex Negation - Fatal编程技术网

Sql server powershell正则表达式错误,DBCC发出警告除外

Sql server powershell正则表达式错误,DBCC发出警告除外,sql-server,regex,powershell,regex-negation,Sql Server,Regex,Powershell,Regex Negation,我正在尝试创建powershell脚本,该脚本将遍历某些Sql Server脚本的日志文件,并调查是否存在word错误。我做到了: Get-Content $log | Select-String "error" -quiet #returns true/false 或 获取内容$log |选择字符串错误返回带有错误的行 问题是我的日志文件还包含来自DBCC的警告,如: 26: DBCC execution completed. If DBCC printed error messages

我正在尝试创建powershell脚本,该脚本将遍历某些Sql Server脚本的日志文件,并调查是否存在word错误。我做到了:

Get-Content $log | Select-String "error" -quiet  #returns true/false
或 获取内容$log |选择字符串错误返回带有错误的行

问题是我的日志文件还包含来自DBCC的警告,如:

 26: DBCC execution completed. If DBCC printed error messages, contact your system administrator.
 24: DBCC execution completed. If DBCC printed error messages, contact your system administrator.
如果DBCC打印了错误消息,如何只列出有错误但没有错误的行? 我尝试过这样的事情:

Get-Content "d:\InsightMasterESF\logs\currentlog.txt" | Select-String -pattern "(error)(?!If DBCC printed error messages)"
但是我不太了解正则表达式的模式。

尝试使用Where对象过滤掉与要排除的文本匹配的行

Get-Content -Path $Log | Where-Object -FilterScript { $PSItem -match 'error' -and $PSItem -notmatch 'If DBCC printed'; };

让我知道这是否有帮助:

Select-String -Path "d:\InsightMasterESF\logs\currentlog.txt" -Pattern error | select-string -Pattern 'If DBCC printed error messages' -NotMatch -Quiet

-NotMatch参数负责处理与DBCC打印的错误消息不匹配的问题。

正则表达式的第一条规则是了解您的数据。如果你需要一个正则表达式的帮助,我们需要确切地知道我们需要匹配的数据是什么样子的。在你发布它之前,我会给出同样的答案。可能需要将-notmatch“DBCC”更改为更具体一点,并将-notmatch“If DBCC printed”设置为-notmatch,这样就不会排除超出所需的内容。@TheMadTechnician:Done:谢谢