Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/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中的日期匹配的所有行_Powershell_Logging - Fatal编程技术网

获取日志中与PowerShell中的日期匹配的所有行

获取日志中与PowerShell中的日期匹配的所有行,powershell,logging,Powershell,Logging,我想从日志文件中获取与日期匹配的所有行。这很好: Get-Content $filepath | Out-String -stream | Select-String $yesterday 但是,当我尝试将其添加到用于输出的字符串中时,它似乎将所有行粘在一行中: $out += Get-Content $filepath | Out-String -stream | Select-String $yesterday 我的方法有问题。我基本上只想从日志文件中获取与我构建的昨天的日期字符串相匹配

我想从日志文件中获取与日期匹配的所有行。这很好:

Get-Content $filepath | Out-String -stream | Select-String $yesterday
但是,当我尝试将其添加到用于输出的字符串中时,它似乎将所有行粘在一行中:

$out += Get-Content $filepath | Out-String -stream | Select-String $yesterday
我的方法有问题。我基本上只想从日志文件中获取与我构建的昨天的日期字符串相匹配的每一行(每一行上都有!)?请问有没有一个简单的好方法

日志的前四行:

10.79.69.226:9300   3096    2021-03-26 07:56:10.058 +1                  Default Executor-thread-6350    caf 2047    2   Audit.dispatcher.caf    Request         Warning     secure error - did not find userCapabilities
10.79.69.226:9300   3096    2021-03-26 07:56:10.136 +1  86CBF1D67841D67F3486E6696FC77CF94E0364CD616B4A2FF18E72D6B40F5D71    88jh8Csq2q2jC4Ch4qysjqyCGdwwvM4lqwM9v8vd        D6F1761A9AB9A34301786A6A8DA18024001786d123647   TaskRunner:61   JSM 12  3   Audit.RTUsage.JSM                   [ContentManagerServiceClientPortImpl] Error when authenticating; response envelope is <?xml version="1.0" encoding="utf-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:faults="http://www.w3.org/2001/09/soap-faults" xmlns:bus="http://developer.cognos.com/schemas/bibus/3/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">   <SOAP-ENV:Header>      <bus:biBusHeader xsi:type="bus:biBusHeader">        <dispatcherTransportVars xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="bus:dispatcherTransportVar[]">           <dispatcherTransportVars xsi:type="bus:dispatcherTransportVar">                 <name xsi:type="xsd:string">requester</name>                <value xsi:type="xsd:string">MS:Run Task</value>            </dispatcherTransportVars>          <dispatcherTransportVars xsi:type="bus:dispatcherTransportVar">                 <name xsi:type="xsd:string">NoQueueing</name>               <value xsi:type="xsd:string">true</value>           </dispatcherTransportVars>                  </dispatcherTransportVars>      <hdrSession xsi:type="bus:hdrSession">          <environmentVars xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="bus:environmentVar[2]">              <environmentVars xsi:type="bus:environmentVar">                     <name xsi:type="xsd:string">SERVER_NAME</name>                  <value xsi:type="xsd:string">localhost</value>              </environmentVars>              <item xsi:type="bus:environmentVar">                    <name xsi:type="xsd:string">WEB_CONTENT_ROOT</name>                     <value xsi:type="xsd:string">/p2pd</value>              </item>             </environmentVars>          <bus:formFieldVars xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="bus:formFieldVar[0]"/>                         <setCookieVars xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="bus:setCookieVar[2]">              <item xsi:type="bus:setCookieVar">                  <name xsi:type="xsd:string">CRN</name>                  <value xsi:type="xsd:string">linesPerPage%3D15%26displayMode%3Dlist%26columnsPerPage%3D3%26showOptionSummary%3Dtrue%26format%3DHTML%26productLocale%3Den%26http%3A%2F%2Fdeveloper.cognos.com%2Fceba%2Fconstants%2FbiDirectionalOptionEnum%23biDirectionalFeaturesEnabled%3Dfalse%26showHints%3DshowAll%26showHiddenObjects%3Dfalse%26http%3A%2F%2Fdeveloper.cognos.com%2Fceba%2Fconstants%2FsystemOptionEnum%23accessibilityFeatures%3Dfalse%26showWelcomePage%3Dtrue%26backgroundSessionLogging%3D1970-01-01%2B00%253A00%253A00%26listViewSeparator%3Dnone%26skin%3Dcorporate%26timeZoneID%3DEurope%252FBerlin%26contentLocale%3Den%26automaticPageRefresh%3D30%26</value>                     <maxAge xsi:type="xsd:int">0</maxAge>               </item>                 <item xsi:type="bus:setCookieVar">                  <name xsi:type="xsd:string">userCapabilities</name>                     <value xsi:type="xsd:string"/>                  <maxAge xsi:type="xsd:int">-1</maxAge>              </item>             </setCookieVars>        </hdrSession>       <tracking xsi:type="bus:tracking">          <hopCount xsi:type="xsd:integer">1</hopCount>           <requestContext xsi:type="xsd:string">2dMqGqCGs4jj2wMjqjGjC9q9ydjjs8qljl4wj2vl</requestContext>             <sessionContext xsi:type="xsd:string">f:1:null</sessionContext>             <providers xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="bus:provider[1]">              <provider xsi:type="bus:provider">                  <name xsi:type="xsd:string">cm</name>                   <patch xsi:type="xsd:int">1</patch>                     <build xsi:type="xsd:string">11.0</build>               </provider>             </providers>        </tracking>         <bus:userPreferenceVars xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="bus:userPreferenceVar[18]">           <item xsi:type="bus:userPreferenceVar">                 <name xsi:type="xsd:string">linesPerPage</name>                 <value xsi:type="xsd:string">15</value>             </item>             <item xsi:type="bus:userPreferenceVar">                 <name xsi:type="xsd:string">displayMode</name>              <value xsi:type="xsd:string">list</value>           </item>             <item xsi:type="bus:userPreferenceVar">                 <name xsi:type="xsd:string">columnsPerPage</name>               <value xsi:type="xsd:string">3</value>          </item>             <item xsi:type="bus:userPreferenceVar">                 <name xsi:type="xsd:string">showOptionSummary</name>                <value xsi:type="xsd:string">true</value>           </item>             <item xsi:type="bus:userPreferenceVar">                 <name xsi:type="xsd:string">format</name>               <value xsi:type="xsd:string">HTML</value>           </item>             <item xsi:type="bus:userPreferenceVar">                 <name xsi:type="xsd:string">productLocale</name>                <value xsi:type="xsd:string">en</value>             </item>             <item xsi:type="bus:userPreferenceVar">                 <name xsi:type="xsd:string">http://developer.cognos.com/ceba/constants/biDirectionalOptionEnum#biDirectionalFeaturesEnabled</name>              <value xsi:type="xsd:string">false</value>          </item>             <item xsi:type="bus:userPreferenceVar">                 <name xsi:type="xsd:string">showHints</name>                <value xsi:type="xsd:string">showAll</value>            </item>             <item xsi:type="bus:userPreferenceVar">                 <name xsi:type="xsd:string">showHiddenObjects</name>                <value xsi:type="xsd:string">false</value>          </item>             <item xsi:type="bus:userPreferenceVar">                 <name xsi:type="xsd:string">http://developer.cognos.com/ceba/constants/systemOptionEnum#accessibilityFeatures</name>                <value xsi:type="xsd:string">false</value>          </item>             <item xsi:type="bus:userPreferenceVar">                 <name xsi:type="xsd:string">http://developer.cognos.com/ceba/constants/biDirectionalOptionEnum#baseTextDirection</name>                 <value xsi:type="xsd:string">http://developer.cognos.com/ceba/constants/baseTextDirectionEnum#Auto</value>          </item>             <item xsi:type="bus:userPreferenceVar">                 <name xsi:type="xsd:string">showWelcomePage</name>              <value xsi:type="xsd:string">true</value>           </item>             <item xsi:type="bus:userPreferenceVar">                 <name xsi:type="xsd:string">backgroundSessionLogging</name>                 <value xsi:type="xsd:string">1970-01-01 00:00:00</value>            </item>             <item xsi:type="bus:userPreferenceVar">                 <name xsi:type="xsd:string">listViewSeparator</name>                <value xsi:type="xsd:string">none</value>           </item>             <item xsi:type="bus:userPreferenceVar">                 <name xsi:type="xsd:string">skin</name>                 <value xsi:type="xsd:string">corporate</value>          </item>             <item xsi:type="bus:userPreferenceVar">                 <name xsi:type="xsd:string">timeZoneID</name>               <value xsi:type="xsd:string">Europe/Berlin</value>          </item>             <item xsi:type="bus:userPreferenceVar">                 <name xsi:type="xsd:string">contentLocale</name>                <value xsi:type="xsd:string">en</value>             </item>             <item xsi:type="bus:userPreferenceVar">                 <name xsi:type="xsd:string">automaticPageRefresh</name>                 <value xsi:type="xsd:string">30</value>             </item>         </bus:userPreferenceVars>       </bus:biBusHeader>  <faults:Misunderstood qname="bus:CM">       <errorDetailDocument xmlns="http://developer.cognos.com/schemas/bibus/3/">          <errorCode>cmAuthenticateTCInvalidReference</errorCode>             <errorMessage>CM-HDR-4012 The search path &quot;CAMID(&quot;ING_PROD:u:uid=ic04yq&quot;)/credential&quot; does not select one credential object.</errorMessage>         </errorDetailDocument>  </faults:Misunderstood>   </SOAP-ENV:Header>   <SOAP-ENV:Body>  <SOAP-ENV:Fault>        <faultcode>Client</faultcode>       <faultstring>CM-REQ-4342 An error occurred with the client.</faultstring>       <detail>            <bus:exception>                 <severity>error</severity>              <errorCode>caf</errorCode>              <bus:message>                   <messageString>CM-REQ-4159 Content Manager returned an error in the response header. The error &quot;cmAuthenticateTCInvalidReference CM-HDR-4012 The search path &quot;CAMID(&quot;ING_PROD:u:uid=ic04yq&quot;)/credential&quot; does not select one credential object.&quot; can be found in the response SOAP header.</messageString>                </bus:message>          </bus:exception>        </detail>   </SOAP-ENV:Fault>   </SOAP-ENV:Body> </SOAP-ENV:Envelope>   
10.79.69.226:9300   3096    2021-03-26 07:56:10.183 +1  B96DF6E61B52E9BF15C76930D9BC5C08C9375906D3F5A04E6B6B5EBC1D50FD60    lsj8jyhswC8vlGdhsqlMvMq4GGqdd2lM2vCdh29C            Default Executor-thread-7091    CM  12  3   Audit.Other.cms.CM  ADD HISTORYDETAIL   /Team Content/Misys reports/7.3/7.3.1182 Facility Overview Detail by Lender_NEW/2021-03-26T06:56:10.089Z/[historyDetail]    Success     
10.79.69.226:9300   3096    2021-03-26 07:56:10.152 +1  86CBF1D67841D67F3486E6696FC77CF94E0364CD616B4A2FF18E72D6B40F5D71    88jh8Csq2q2jC4Ch4qysjqyCGdwwvM4lqwM9v8vd        D6F1761A9AB9A34301786A6A8DA18024001786d123647   TaskRunner:61   MS  12  3   Audit.RTUsage.ms.MS                 Failed to run task [com.cognos.monitor.tse.BiBusRunContext taskID=D6F1761A9AB9A34301786A6A8DA18024001786d123647].  Error is: CNC-MON-3600 An error occurred running the object on the target service. Consult the log files.    
10.79.69.226:9300 3096 2021-03-26 07:56:10.058+1默认执行器-thread-6350 caf 2047 2 Audit.dispatcher.caf请求警告安全错误-未找到用户功能
10.79.69.226:9300 3096 2021-03-26 07:56:10.136+1 86CBF1D6784D67F3486E6696FC77CF94E0364CD616B4A2FF18E72D60F5D71 88JH8CSQ2Q2JC4CH4QYSJQYCGDWVM4QWM9V8VD D6f16lang1024 9AB9A301786A8DA18024001786D123647任务运行者:61 JSM 12 3 Audit.RTUsage.JSM[ContentManagerService ClientImpl]验证时出错;响应信封是请求者MS:runtask NoQueueing true SERVER\u NAME localhostWEB\u内容\u根目录/p2pd CRNlinesPerPage%3D15%26显示模式%3Dlist%26列sperpage%3D3%26显示选项摘要%3Dtrue%26格式%3DHTML%26产品区域设置%3Den%26http%3A%2F%2Fdeveloper.cognos.com%2Fceba%2Fconstants%2FbiDirectionalOptionEnum%23双向特性启用%3Dfalse%26显示提示%3DshowAll%26showHiddenObjects%3Dfalse%26http%3A%2F%2Fdeveloper.cognos.com%2Fceba%2Fconstants%2SystemOptionenum%23可访问性功能%3Dfalse%26显示欢迎页面%3Dtrue%26背景会话记录%3D1970-01-01%2B00%253A00%253A00%253A00%26列表视图分隔符%3Dnone%26外观%3Dcorporate%26时区ID%3deope%252FBerlin%26内容区域设置%3Den%26自动更新%3D30%26 0userCapabilities-1 1 2dMqGqCGs4jj2wMjqjGjC9q9ydjjs8qljl4wj2vl f:1:null cm 1 11.0linesPerPage 15显示模式列表列PerPage 3显示选项摘要真实格式HTML产品地点http://developer.cognos.com/ceba/constants/biDirectionalOptionEnum#biDirectionalFeaturesEnabled              false showHits showAll showHiddenObject false                                      http://developer.cognos.com/ceba/constants/systemOptionEnum#accessibilityFeatures                假的http://developer.cognos.com/ceba/constants/biDirectionalOptionEnum#baseTextDirection                 http://developer.cognos.com/ceba/constants/baseTextDirectionEnum#Auto                                        showWelcomePage真实背景会话记录1970-01-01 00:00:00列表视图分隔符无skin corporate timeZoneID Europe/Berlin contentLocale en automaticPageRefresh 30CMAuthenticateTInvalidReference CM-HDR-4012搜索路径“CAMID(“ING_PROD:u:uid=ic04yq”)/credential”未选择一个凭证对象。客户端CM-REQ-4342客户端出现错误。错误caf CM-REQ-4159内容管理器在响应标头中返回错误。在响应SOAP标头中可以找到错误“CMAuthenticateTInvalidReference CM-HDR-4012搜索路径”CAMID(“ING_PROD:u:uid=ic04yq”)/credential“未选择一个凭据对象”。
10.79.69.226:9300 3096 2021-03-26 07:56:10.183+1 B96DF6E61B52E9BF15C76930D9BC5C08C9375906D3F5A04E6B6B5EBC1D50FD60 LSJ8JYHSWC8VLGDHSQLMMQ4GGQDD2LM2VCDH29C默认执行器线程-7091厘米12 3审计。其他cms.CM添加历史细节/团队内容/Misys报告/7.3/7.3/7.3.3.1182设施概览细节贷方_NEW/2021-03-26T06:56:10.089Z/[历史细节]成功
10.79.69.226:9300 3096 2021-03-26 07:56:10.152+1 86CBF1D6784D67F3486E6696FC77CF94E0364CD616B4A2FF18E72D6B40F5D71 88JH8CSQ2Q2JC4CH4QYSJQYCGDWVM4QWM9V8VD D6f16lang1024 9AB9A301786A8DA18024001786D123647任务运行程序:61 MS 12 3 Audit.rtuage.MS.MS无法运行任务[com.cognos.monitor.tse.BiBusRunContext taskID=D6f16lang1024 1A9AB9A34301786A6A8DA18024001786D123647]。错误为:CNC-MON-3600在目标服务上运行对象时出错。请参阅日志文件。

这不算答案,但我想这很容易用截图来解释。如果您理解截图中的内容,请告诉我
$yesterday = '{0:yyyy-MM-dd}' -f (Get-Date).AddDays(-1)
$log = Get-Content -Path $filepath
$out = Join-Path -Path ([System.IO.Path]::GetDirectoryName($filepath)) -ChildPath ("log_{0}.log" -f $yesterday)
# use SimpleMatch because the pattern is to be taken literally (no regex)
($log | Select-String -Pattern $yesterday -SimpleMatch).Line | Set-Content -Path $out
$yesterday = '{0:yyyy-MM-dd}' -f (Get-Date).AddDays(-1)
$out = Join-Path -Path ([System.IO.Path]::GetDirectoryName($filepath)) -ChildPath ("log_{0}.log" -f $yesterday)
# use SimpleMatch because the pattern is to be taken literally (no regex)
(Select-String -Path $filepath -Pattern $yesterday -SimpleMatch).Line | Set-Content -Path $out