我的foreach循环将所有内容日志添加到单行。如何修复它以向索引添加内容?
$FilterHashTable = @{logname='Application'; providername='Microsoft-Windows- SoftwareRestrictionPolicies'; StartTime=$StartTime};
$test = Invoke-Command -ScriptBlock {param ($FilterHashTable) Get-WinEvent -FilterHashtable $FilterHashTable} -ArgumentList $FilterHashTable -ComputerName 491-517 |
Select-Object PSComputerName, TimeCreated, Message
foreach ($id in $test)
{
$PSComputerName = $test.PSComputerName
$TimeCreated = $test.TimeCreated
$Message = $test.Message
Add-Content $logFile "$PSComputerName, $TimeCreated, $Message"
}