I used powershell in version 2009 and use Group-object in my script.
$todaye = (Get-Date -Hour 0 -Minute 00 -Second 00)
$yesterday = $todaye.AddDays(-1)
$EventLogs = 'Operations Manager'
$csv = @()
$strlog = $EventLogs.Split(',')
foreach($log in $strlog)
{
$log | ForEach-Object{ get-eventlog -log $_ -After $yesterday -
Before $todaye | Group-Object EventID,EntryType,Source,MachineName,
{(([String]$_.TimeGenerated) -split " ")[0]},
{(([String]$_.TimeGenerated) -split " ")[1]}, $_ -NoElement |
Sort-Object Count -Descending |
Select-Object count,name | ForEach-Object{
$properties = @{
'ServerName' = ($_.Name -split ", ")[3];
'day' = (($_.Name -split ", ")[4] -split " ")[0];
'time' = (($_.Name -split ", ")[5]);
'EventID' = ($_.Name -split ", ")[0];
'EventType' = ($_.Name -split ", ")[1];
'Source' = ($_.Name -split ", ")[2];
'Count' = $_.Count;
}
$psobject = new-object psobject -Property $properties
$csv += $psobject
}
}
}
after I run my script I have the below error.
Group-Object : Cannot convert System.Management.Automation.PSObject to one
of the following types {System.String,
System.Management.Automation.ScriptBlock}.
I run my script in powersell 2012 and didn't any errors. how can I do for solve this error.
从第二行{(([String]$_.TimeGenerated)
删除$_
,然后它将在powershell 2上运行,如下所示:
{(([String]$_.TimeGenerated) -split " ")[1]} -NoElement
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.