Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 如何修复foreach循环_Powershell - Fatal编程技术网

Powershell 如何修复foreach循环

Powershell 如何修复foreach循环,powershell,Powershell,我的foreach循环将所有内容日志添加到一行。如何将内容添加到索引中 $FilterHashTable = @{logname='Application'; providername='Microsoft-Windows- SoftwareRestrictionPolicies'; StartTime=$StartTime}; $test = Invoke-Command -ScriptBlock {param ($FilterHashTable) Get-WinEvent -Filter

我的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"
}
看看那里:

$id
是列表中的下一个元素,请参阅
$id
而不是
$test

试试这个

foreach ($id in $test)
{

$PSComputerName = $id.PSComputerName
$TimeCreated = $id.TimeCreated
$Message = $id.Message

Add-Content $logFile  "$PSComputerName, $TimeCreated, $Message"
}

“将内容添加到索引”是什么意思?嗯,我把所有日志都放在一行。我必须让它像有多少日志一样多行。我不知道如何解释。不像这个cpu1,cpu1 | time,time | message,message而是cpu1,time,message cpu1,time,message cpu2,time,message这就是我的意思。谢谢没问题,伙计