kreatd / transfer

0 stars 0 forks source link

J #2

Open kreatd opened 3 weeks ago

kreatd commented 3 weeks ago

Yes, here's that part (modules are ExchangeOnlineManagement and PSWriteHTML):

# Get all message traces in the above time period

Get-QuarantineMessage -StartReceivedDate $dateStart -EndReceivedDate $dateEnd |

Select ReceivedTime,SenderAddress,RecipientAddress,Subject,QuarantineTypes |

Sort-Object -Descending ReceivedTime -OutVariable allTraces

# Function to convert UTC to EST (place this outside the Get-QuarantineMessage command)

function ConvertUtcToEst($utcTime) {

[TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($utcTime, 'Eastern Standard Time')

}

# Loop through each message and convert ReceivedTime to EST, creating a new collection

$allTracesConverted = @()

foreach ($trace in $allTraces) {

# Convert UTC ReceivedTime to EST

$estReceivedTime = ConvertUtcToEst $trace.ReceivedTime

# Create a new object with EST ReceivedTime and other properties

$newTrace = New-Object PSObject -Property @{

ETReceivedTime = $estReceivedTime.ToString("yyyy-MM-dd,HH:mm:ss")

SenderAddress = $trace.SenderAddress

RecipientAddress = $trace.RecipientAddress

Subject = $trace.Subject

QuarantineTypes = $trace.QuarantineTypes

}

$newTrace = $newTrace | Select-Object ETReceivedTime, SenderAddress, RecipientAddress, Subject, QuarantineTypes

# Add the new object with converted time to the $allTracesConverted collection

$allTracesConverted += $newTrace

}