-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds abilityt to parse and write simple_user_changes and user_changes…
…. User changes still has raw auditlog blob in it.
- Loading branch information
1 parent
51546a6
commit e96ee88
Showing
2 changed files
with
80 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,69 +8,78 @@ | |
.PARAMETER UserPrincipalName | ||
UserPrincipalName of the user you're investigating | ||
.OUTPUTS | ||
File: Simple_User_Changes.csv | ||
Path: <user> | ||
Path: \<user> | ||
Description: All cmdlets that were run against the user in a simple format. | ||
File: User_Changes.csv | ||
Path: \<user> | ||
Description: Raw data of all changes made to the user. | ||
File: User_Changes_Raw.json | ||
Path: \<user> | ||
Description: Raw JSON data from audit logs. | ||
File: User_Changes_Raw.txt | ||
Path: \<user> | ||
Description: Human readable format of raw audit data. | ||
.EXAMPLE | ||
Get-HawkUserAdminAudit -UserPrincipalName [email protected] | ||
Gets all changes made to [email protected] and outputs them to the csv and json files. | ||
#> | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[array]$UserPrincipalName | ||
) | ||
|
||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[array]$UserPrincipalName | ||
) | ||
Test-EXOConnection | ||
Send-AIEvent -Event "CmdRun" | ||
|
||
Test-EXOConnection | ||
Send-AIEvent -Event "CmdRun" | ||
# Verify our UPN input | ||
[array]$UserArray = Test-UserObject -ToTest $UserPrincipalName | ||
|
||
# Verify our UPN input | ||
[array]$UserArray = Test-UserObject -ToTest $UserPrincipalName | ||
foreach ($Object in $UserArray) { | ||
[string]$User = $Object.UserPrincipalName | ||
|
||
foreach ($Object in $UserArray) { | ||
[string]$User = $Object.UserPrincipalName | ||
# Get the mailbox name since that is what we store in the admin audit log | ||
$MailboxName = (Get-Mailbox -Identity $User).Name | ||
|
||
# Get the mailbox name (used previously) | ||
$MailboxName = (Get-Mailbox -Identity $User).Name | ||
Out-LogFile ("Searching for changes made to: " + $MailboxName) -action | ||
|
||
Out-LogFile ("Searching for changes made to: " + $MailboxName) -action | ||
# Get all changes for this user | ||
[array]$UserChanges = Search-UnifiedAuditLog -UserIds $User -StartDate $Hawk.StartDate -EndDate $Hawk.EndDate -RecordType ExchangeAdmin -Operations "*" -ResultSize 5000 | ||
|
||
# Get all changes for this user from the Unified Audit Logs | ||
[array]$UserChanges = Search-UnifiedAuditLog -UserIds $User -StartDate $Hawk.StartDate -EndDate $Hawk.EndDate -RecordType ExchangeAdmin -Operations "*" -ResultSize 5000 | ||
# If there are any results push them to an output file | ||
if ($UserChanges.Count -gt 0) { | ||
Out-LogFile ("Found " + $UserChanges.Count + " changes made to this user") | ||
|
||
# If there are any results, handle them | ||
if ($UserChanges.Count -gt 0) { | ||
Out-LogFile ("Found " + $UserChanges.Count + " changes made to this user") | ||
# Get the user's output folder path | ||
$UserFolder = Get-HawkUserPath -User $User | ||
|
||
# Determine the user's output folder | ||
$UserFolder = (Get-HawkUserPath -User $User) | ||
# Write raw AuditData to files for verification/debugging | ||
$RawJsonPath = Join-Path -Path $UserFolder -ChildPath "User_Changes_Raw.json" | ||
$UserChanges | Select-Object -ExpandProperty AuditData | Out-File -FilePath $RawJsonPath | ||
|
||
# Write raw AuditData JSON to a JSON file for verification | ||
$RawJsonPath = Join-Path $UserFolder "User_Changes_Raw.json" | ||
$UserChanges | Select-Object -ExpandProperty AuditData | Out-File $RawJsonPath | ||
$RawTxtPath = Join-Path -Path $UserFolder -ChildPath "User_Changes_Raw.txt" | ||
"User: $User" | Out-File -FilePath $RawTxtPath | ||
$UserChanges | Select-Object -ExpandProperty AuditData | Out-File -FilePath $RawTxtPath -Append | ||
"------------------------------------" | Out-File -FilePath $RawTxtPath -Append | ||
|
||
# Also write raw data to a text file (similar to previous testing snippet) | ||
$RawTxtPath = Join-Path $UserFolder "User_Changes_Raw.txt" | ||
"User: $User" | Out-File $RawTxtPath | ||
$UserChanges | Select-Object -ExpandProperty AuditData | Out-File $RawTxtPath -Append | ||
"------------------------------------" | Out-File $RawTxtPath -Append | ||
# Parse and format the changes using Get-SimpleUnifiedAuditLog | ||
$ParsedChanges = $UserChanges | Get-SimpleUnifiedAuditLog | ||
|
||
# Parse the results with the new Get-SimpleUnifiedAuditLog function | ||
$ParsedChanges = $UserChanges | ForEach-Object { | ||
$AuditDataJson = $_.AuditData | ||
$AuditDataObj = $AuditDataJson | ConvertFrom-Json | ||
$AuditDataObj | ||
} | Get-SimpleUnifiedAuditLog | ||
|
||
# Output the parsed results | ||
# Output the processed results | ||
if ($ParsedChanges) { | ||
$ParsedChanges | Out-MultipleFileType -FilePrefix "Simple_User_Changes" -csv -json -User $User | ||
$UserChanges | Out-MultipleFileType -FilePrefix "User_Changes" -csv -json -User $User | ||
} | ||
else { | ||
Out-LogFile "No User Changes found." | ||
} | ||
|
||
# Output the raw changes | ||
$UserChanges | Out-MultipleFileType -FilePrefix "User_Changes" -csv -json -User $User | ||
} | ||
else { | ||
Out-LogFile "No User Changes found." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters