繁体   English   中英

Windows 命令行 Powershell 错误:表达式中缺少关闭“)”

[英]Windows Command Line Powershell error: Missing closing ')' in expression

我无法将其格式化为作为单个命令行运行。

powershell ("$today = [system.datetime](Get-Date); $startTime = $today.AddHours(-4); Get-WinEvent -FilterHashtable @{LogName='Application'; ProviderName='Application Error';Data='internalProcess.exe';StartTime=$startTime;EndTime=$today}")

我看到这个错误:

At line:1 char:38
+ ($today = [system.datetime](Get-Date); $startTime = $today.AddHours(- ...
+                                      ~
Missing closing ')' in expression.

我不清楚问题是什么。 当我在 PowershellISE 中运行它时,它只是没有在我的笔记本电脑上找到具有该名称的进程。

在 powershell ISE 中:

$today = [system.datetime](Get-Date); $startTime = $today.AddHours(-100); Get-WinEvent -FilterHashtable @{LogName='Application'; ProviderName='Application Error';StartTime=$startTime;EndTime=$today}

Get-WinEvent : No events were found that match the specified selection criteria.
At K:\Cleary\BlobScans\69xxNotFoundEDCS\WinEvents.ps1:21 char:75
+ ... ours(-100); Get-WinEvent -FilterHashtable @{LogName='Application'; Pr ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:) [Get-WinEvent], Exception
    + FullyQualifiedErrorId : NoMatchingEventsFound,Microsoft.PowerShell.Commands.GetWinEventCommand

我可以在设备上没有日期部分的情况下运行命令:

powershell ("Get-WinEvent -FilterHashtable @{LogName='Application'; ProviderName='Application Error';Data='internalProcess.exe'}")

(没有错误......它列出了 3 个应用程序错误,日期为 2022 年 7 月 23 日)

我尝试在 powershell 中将时间更改为 -130 小时:

powershell ("$today = [system.datetime](Get-Date); $startTime = $today.AddHours(-4); Get-WinEvent -FilterHashtable @{LogName='Application'; ProviderName='Application Error';Data='internalProcess.exe';StartTime=$startTime;EndTime=$today}")

我仍然看到同样的错误:

At line:1 char:38
+ ($today = [system.datetime](Get-Date); $startTime = $today.AddHours(- ...
+                                      ~
Missing closing ')' in expression.

如何格式化要在 windows 命令行上运行的行,这样它就不会认为它缺少右括号?

括号位置需要在调用运行 PowerShell.exe 之前而不是之后。 因为它是 PowerShell 将其解释为语法的一部分,这是不对的。 您需要 cmd 将其作为一个分组读取,以使用指定的命令运行 powershell 。 将括号移到 PowerShell 之前以修复语法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM