在下面的代码中寻找信息,它实际上做了预期的事情。它检索过去 7 天的“CreateTimesheets”任务的持续时间。但是,它以错误消息结束。
Get-WinEvent -FilterHashtable @{
'LogName' = 'Microsoft-Windows-TaskScheduler/Operational'
'ID' = 200, 201
'StartTime' = [datetime]::Today.AddDays(-7)
'EndTime' = [datetime]::Today
} | Group-Object ActivityID | ForEach-Object {
if($_.Group.Properties[0].Value -like '*CreateTimesheets*'){
$start = $_.Group |
Where-Object { $_.Id -eq 200 } |
Select-Object -Expand TimeCreated -First 1
$end = $_.Group |
Where-Object { $_.Id -eq 201 } |
Select-Object -Expand TimeCreated -First 1
New-Object -Type PSObject -Property @{
'TaskName' = $_.Group[0].Properties[0].Value
'StartTime' = $start
'Duration' = ($end - $start).TotalSeconds
} }
}
错误信息如下
Cannot find an overload for "op_Subtraction" and the argument count: "2".
At line:15 char:12
+ New-Object -Type PSObject -Property @{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
我对powershell脚本很陌生,并且在其他堆栈溢出问题上发现了相同的错误消息,但场景似乎与此完全不同,有人可以帮我解决这个问题吗?谢谢