2017-10-26 4 views
0

4つではなく1つのアウトグリッドビューに結果を出力する必要があるまでは、お知らせ下さい。4つの独立したものの代わりに1つのアウトグリッドビューに4つの結果が表示される必要があります

$Date = (Get-Date -format "MM-dd-yyyy") 

$FileContent = Get-Content "c:\temp\$date.txt" 
$AdminMatches = Select-String -InputObject $FileContent -Pattern "Administrative" -AllMatches 
$AdminMatches.Matches.Count * 15/60 | Out-GridView 

$ProjectMatches = Select-String -InputObject $FileContent -Pattern "Project" -AllMatches 
$ProjectMatches.Matches.Count * 15/60 | Out-GridView 

$SustainMatches = Select-String -InputObject $FileContent -Pattern "Sustain" -AllMatches 
$SustainMatches.Matches.Count * 15/60 | Out-GridView 

$PaidMatches = Select-String -InputObject $FileContent -Pattern "Paid" -AllMatches 
$PaidMatches.Matches.Count * 15/60 | Out-GridView 

答えて

2

ただ、パイプ、そのout-gridviewにすべてのあなたのカウントを収集し、オブジェクトを作成して:

[pscustomobject]@{"adminCount" = $AdminMatches.Matches.Count * 15/60; "projectMatches" = $ProjectMatches.Matches.Count * 15/60; "sustainMatchesCount" = $SustainMatches.Matches.Count * 15/60; "paidMatchedCount" = $PaidMatches.Matches.Count * 15/60;} | Out-GridView 
+0

@zdan – NobleMan

1

動的メソッドを(あなたはあなたの言葉のリストを変更することができ、そのはまだ動作)。ファイル内の検索は1つだけ実行されます(パフォーマンスは向上します)。

$File ="c:\temp\{0:MM-dd-yyyy}.txt" -f (Get-Date) 
$words="Administrative","Project","Sustain","Paid" 

$Countvalues=Select-String $File -Pattern ($words -join "|") -AllMatches | %{ $_.Matches.Groups} | group Value 

$Objet=[pscustomobject]@{} 

foreach ($word in $words) 
{ 
$Nb=($Countvalues | where name -eq $word).Count/$words.Count 
$Objet | Add-Member -MemberType NoteProperty -Name $word -Value $Nb  
} 

$Objet | Out-GridView 
関連する問題