PowerShell脚本在Windows事件日志中产生大量的警告

我有一个相当复杂的Windows Server 2008 R2上运行的PowerShell脚本。 在ISE中或在控制台中执行脚本时,一切运行良好。 没有错误或其他任何突出的东西。

但是,在Windows事件查看器中,很多警告正在生成,没有任何特定的原因,我可以看到。

Log Name: Microsoft-Windows-PowerShell/Operational Source: PowerShell (Microsoft-Windows-PowerShell) Event ID: 4100 Task Category: Executing Pipeline Error Message = System error. Context: Severity = Warning Host Name = Windows PowerShell ISE Host Host Version = 4.0 Host ID = cec010f3-ea0f-44b0-8d2e-449a6c1eb3e6 Engine Version = 4.0 Runspace ID = b2e8d39c-4fa1-4a3f-b33e-b42f8b552c3d Pipeline ID = 17 Command Name = Command Type = Script Name = Command Path = Sequence Number = 92 User = [the executing user] Shell ID = Microsoft.PowerShell User Data: 

谷歌没有透露任何东西。 有没有人有一个想法这可能意味着什么? 正如我所说,这些条目有胡扯。 让我知道如果我应该发布更多。

非常感谢!

编辑:按要求整个事件的XML

 <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="Microsoft-Windows-PowerShell" Guid="{A0C1853B-5C40-4B15-8766-3CF1C58F985A}" /> <EventID>4100</EventID> <Version>1</Version> <Level>3</Level> <Task>106</Task> <Opcode>19</Opcode> <Keywords>0x0</Keywords> <TimeCreated SystemTime="2015-03-16T14:06:07.066866300Z" /> <EventRecordID>1994921</EventRecordID> <Correlation ActivityID="{01EC0C48-F800-0001-6B28-234CAE5DD001}" /> <Execution ProcessID="6528" ThreadID="5376" /> <Channel>Microsoft-Windows-PowerShell/Operational</Channel> <Computer>[host]</Computer> <Security UserID="S-1-5-21-1482476501-1450960922-725345543-2410959" /> </System> <EventData> <Data Name="ContextInfo">Severity = Warning Host Name = Windows PowerShell ISE Host Host Version = 4.0 Host ID = cec010f3-ea0f-44b0-8d2e-449a6c1eb3e6 Engine Version = 4.0 Runspace ID = b2e8d39c-4fa1-4a3f-b33e-b42f8b552c3d Pipeline ID = 36 Command Name = Command Type = Script Name = Command Path = Sequence Number = 7665 User = [user name] Shell ID = Microsoft.PowerShell</Data> <Data Name="UserData" /> <Data Name="Payload">Error Message = System error.</Data> </EventData> </Event> 

增加了PS D:\Autonomy\cd_provisioning_client> ($PsVersionTable)

 Name Value ---- ----- PSVersion 4.0 WSManStackVersion 3.0 SerializationVersion 1.1.0.1 CLRVersion 4.0.30319.34209 BuildVersion 6.3.9600.16406 PSCompatibleVersions {1.0, 2.0, 3.0, 4.0} PSRemotingProtocolVersion 2.2 

powershell_ise.exe.config

 <?xml version="1.0" encoding="utf-8" ?> <configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0" /> </startup> </configuration> 

在ISE中或在控制台中执行脚本时,一切运行良好。 没有错误或其他任何突出的东西。

运行良好并不意味着没有遇到错误。 您的脚本可能只是忽略它们,使用-ErrorAction SilentlyContinue参数与cmdlet。 例:

 Get-ChildItem -LiteralPath ZZZ:\ 

这将产生所谓的终止错误 ,并将停止当前的pipe道,但由于ErrorActionPreferencevariables默认设置为Continue ,脚本本身将继续执行。 而且,正如您所看到的,PowerShell主机会将此错误logging到事件日志中。

如果您想debugging您的脚本并查找导致此日志logging的错误,请在脚本开始处将$ErrorActionPreference设置$ErrorActionPreference Stop ,然后运行它。 遇到的第一个错误将停止脚本执行,然后您可以查看错误的详细信息,如$Error[0]

更新:我亏损了,因为我们所做的一切都没有导致实质性的结果:

  • $Errorvariables是空的
  • Set-StrictMode -Version Latest没有收到任何东西
  • $PsVersionTablepowershell_ise.config在我看来很好

这绝对是一件奇怪的事情,我不相信这些空的领域是正常的:

 Command Name = Command Type = Script Name = Command Path = 

虽然我还有一些想法可以尝试,但是需要更深入的研究:

  • 检查脚本中是否有任何非PowerShell对象\方法(第三方程序集,COM对象等),并尝试将其注释掉。
  • 尝试使用Process Monitor监视PowerShell进程

祝你好运!