Skip to content

Commit

Permalink
Modify UAL common schema parameters to be in order within CSV as per …
Browse files Browse the repository at this point in the history
…the direction of our Lord and Savior, the Cloud Messiah himself, and Ruling Cloud Architect, Paul Navarro.
  • Loading branch information
jonnybottles committed Dec 11, 2024
1 parent 44b9aeb commit 19a1aa1
Showing 1 changed file with 62 additions and 5 deletions.
67 changes: 62 additions & 5 deletions Hawk/internal/functions/Get-SimpleUnifiedAuditLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,74 @@
# Handle and log any processing errors
Write-Warning "Error processing record: $_"
$errorProperties = @{
RecordType = $Record.RecordType
RecordType = $Record.RecordType
CreationDate = Get-Date
Error = $_.Exception.Message
Record = $Record
Error = $_.Exception.Message
Record = $Record
}
$Results += [PSCustomObject]$errorProperties
}
}

end {
# Return all processed results
$Results
# Define the ordered common schema properties
$orderedProperties = @(
'CreationTime',
'Workload',
'RecordType',
'Operation',
'ResultStatus',
'ClientIP',
'UserId',
'Id',
'OrganizationId',
'UserType',
'UserKey',
'ObjectId',
'Scope',
'AppAccessContext'
)

# Process each result to ensure proper property ordering
$orderedResults = $Results | ForEach-Object {
$orderedObject = [ordered]@{}

# Add ordered common schema properties first
foreach ($prop in $orderedProperties) {
if ($_.PSObject.Properties.Name -contains $prop) {
$orderedObject[$prop] = $_.$prop
}
}

# Add ParameterString if it exists
if ($_.PSObject.Properties.Name -contains 'ParameterString') {
$orderedObject['ParameterString'] = $_.ParameterString

# Add all Param_* properties immediately after ParameterString
$_.PSObject.Properties |
Where-Object { $_.Name -like 'Param_*' } |
Sort-Object Name |
ForEach-Object {
$orderedObject[$_.Name] = $_.Value
}
}

# Add all remaining properties that aren't already added
$_.PSObject.Properties |
Where-Object {
$_.Name -notin $orderedProperties -and
$_.Name -ne 'ParameterString' -and
$_.Name -notlike 'Param_*'
} |
ForEach-Object {
$orderedObject[$_.Name] = $_.Value
}

# Return the ordered object
[PSCustomObject]$orderedObject
}

# Return all processed results with ordered properties
$orderedResults
}
}

0 comments on commit 19a1aa1

Please sign in to comment.