По сути, у меня есть сценарий, который я собираю, который будет выполнять трассировку для всех наших серверов Exchange, он предназначен для агентов, использующих удаленный Powershell, поскольку в сценарии не поддерживается конвейер.
С этим я сохраняю результаты в массиве перед экспортом в CSV, проблема в том, что получатели сами по себе являются массивом.
Итак, мой вопрос - как мне ссылаться на массив внутри массива, чтобы поместить получателей в экспортированный CSV. В моем текущем сценарии написаны следующие столбцы:
Метка времени сервера. Идентификатор источника. Получатели отправителя. MessageSubject
Затем в столбец получателей добавляется:
@{Recipients=System.Collections.ArrayList}
Param (
[Parameter(Mandatory=$True)]
[ValidateNotNull()]
[String]$Start,
[Parameter(Mandatory=$True)]
[ValidateNotNull()]
[String]$End,
[Parameter(Mandatory=$True)]
[ValidateNotNull()]
[String]$Sender,
[Parameter(Mandatory=$False)]
[ValidateNotNull()]
[String]$Recipient,
[Parameter(Mandatory=$False)]
[ValidateNotNull()]
[String]$Subject
)
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri <HostAddress> -Authentication basic -Credential $UserCredential
Import-PSSession $Session -DisableNameChecking
$ifBlock = "0"
$tracingResults = @()
#Get-ExchangeServer | Select Name
#ForEach ($S in (Get-ExchangeServer | select -ExpandProperty name))
if (($Recipient -eq "" -And $Subject -eq "") -And ($ifBlock -eq "0" -or $ifBlock -eq "R+S"))
{
$ifBlock = "R+S"
ForEach ($S in (Get-ExchangeServer | select -ExpandProperty name)){
$Tracing = Get-MessageTrackingLog -ResultSize Unlimited -server $S -Start $Start -End $End -Sender $Sender | select Timestamp,ServerHostname,EventId,Source,Sender,Recipients,MessageSubject
if ($tracing -eq ""){
Write-Output ($S + " : No emails found here")
}
if ($Tracing -ne ""){
$TracingObject = Get-Variable Tracing
try{
$tracingResults += New-Object -TypeName PSObject -Property @{
Server = $S
Timestamp = $TracingObject.Value[0] | select Timestamp
EventId = $TracingObject.Value[0] | select EventId
Source = $TracingObject.Value[0] | select Source
Sender = $TracingObject.Value[0] | select Sender
Recipients = $TracingObject.Value[0] | select Recipients
MessageSubject = $TracingObject.Value[0] | select MessageSubject
} | Select-Object Server,Timestamp,EventId,Source,Sender,Recipients,MessageSubject
}
catch{}
#Write-Output ($tracing)
}
}
}
Remove-PSSession $Session
$tracingResults | Export-Csv -NoTypeInformation -Path ./trace.csv