1
我在版本2009中使用了powershell,並在我的腳本中使用了Group-object。Group-object cmdlet的結果不一致
$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
}
}
}
我運行我的腳本後我有下面的錯誤。
Group-Object : Cannot convert System.Management.Automation.PSObject to one
of the following types {System.String,
System.Management.Automation.ScriptBlock}.
我跑我的powersell 2012腳本,並沒有任何錯誤。我該如何解決這個錯誤。
'{(([字符串] $ _ TimeGenerated)-split「「)[1 ]},$ _ - NonElement' - >'{(([String] $ _。TimeGenerated)-split「」)[1]} - NonElement' – PetSerAl