Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/151- Ensure all scripts use UTC time instead of local time #203

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
cb960ef
bugfix/151: Ensure all scripts use UTC time and update related files
Ahamedur Dec 13, 2024
f442925
bugfix/151: Added Word file with screenshots for review
Ahamedur Dec 13, 2024
92aa205
Restored tests folder and updated .gitignore.
Ahamedur Dec 15, 2024
56b79db
Reverted UTC changes in specific files to match Development branch.
Ahamedur Dec 15, 2024
5e32481
Fixed UTC conversion issues in Initialize-HawkGlobalObject function
Ahamedur Dec 15, 2024
ae1d434
Fixed UTC conversion issues in Out-LogFile.ps1
Ahamedur Dec 15, 2024
a83f3a8
Merge branch 'Development' into bugfix/151-ensure-all-scripts-use-utc…
Ahamedur Dec 15, 2024
5ed00b5
Fix MissingEqualsInHashLiteral error in Initialize-HawkGlobalObject.ps1
Ahamedur Dec 15, 2024
9ef4743
Resolved merge conflict in Initialize-HawkGlobalObject.ps1
Ahamedur Dec 15, 2024
4b6b4c3
Fix: Addressed PSScriptAnalyzer warning for EndDate usage in Initiali…
Ahamedur Dec 15, 2024
8fc3890
Fix: Resolved PSScriptAnalyzer warning by actively using EndDate in I…
Ahamedur Dec 15, 2024
a58f426
Fix: Removed unused EndDate logic to resolve PSScriptAnalyzer warnings
Ahamedur Dec 15, 2024
414c029
Fix: Handle invalid paths and add debug logging for Import-ModuleFile
Ahamedur Dec 15, 2024
007831d
Fix: Handle invalid paths and add debug logging for Import-ModuleFile
Ahamedur Dec 15, 2024
9a4b81b
Restored license.ps1 as original format.
Ahamedur Dec 16, 2024
e554962
Fixed encoding and passed PSScriptAnalyzer checks
Ahamedur Dec 18, 2024
af6f6c0
Merge branch 'Development' into bugfix/151-ensure-all-scripts-use-utc…
Ahamedur Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are good. No issues here.

Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ Hawk/Hawk.psproj
TestResults/*

# ignore the publishing Directory
publish/*
publish/*

# Ignore specific file types
*.csv
*.json
*.docx
*.xlsx
11 changes: 8 additions & 3 deletions Hawk/Hawk.psm1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious as to what these changes are for? This doesn't fix UTC issues, please let me know what the changes are for.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not modify any code here; I simply aligned the # characters, which resolved the following issue:

calling "InvokeScript" with "4" argument(s): "The term '<#' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again."
At C:\Projects\hawk\Hawk\hawk.psm1:76 char:9

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
$script:ModuleRoot = $PSScriptRoot
$script:ModuleRoot = $PSScriptRoot
$script:ModuleVersion = (Import-PowerShellDataFile -Path "$($script:ModuleRoot)\Hawk.psd1").ModuleVersion

# Detect whether at some level dotsourcing was enforced
$script:doDotSource = Get-PSFConfigValue -FullName Hawk.Import.DoDotSource -Fallback $false
if ($Hawk_dotsourcemodule) { $script:doDotSource = $true }
Expand Down Expand Up @@ -47,7 +46,13 @@ function Import-ModuleFile

$resolvedPath = $ExecutionContext.SessionState.Path.GetResolvedPSPathFromPSPath($Path).ProviderPath
if ($doDotSource) { . $resolvedPath }
else { $ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText($resolvedPath))), $null, $null) }
else {try {
$content = [io.file]::ReadAllText($resolvedPath)
$scriptBlock = [scriptblock]::Create($content)
$ExecutionContext.InvokeCommand.InvokeScript($false, $scriptBlock, $null, $null)
} catch {
Write-Error "Failed to import: $resolvedPath. Error: $_"
}}
}

#region Load individual files
Expand Down
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes were made to this file that were not associated with this ticket, please revert these changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't change

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
[array]$RoleAssignements = $null

# Look for E-Discovery Roles and who they might be assigned to
$EDiscoveryCmdlets = "New-MailboxSearch", "Search-Mailbox"
$EDiscoveryCmdlets = "New-ComplianceSearch", "New-ComplianceSearchAction"

# Find any roles that have these critical ediscovery cmdlets in them
# Bad actors with sufficient rights could have created new roles so we search for them
Expand Down
101 changes: 101 additions & 0 deletions Hawk/internal/functions/AuditLog.csv
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be in the repo, this is an output file from hawk being ran.

Large diffs are not rendered by default.

101 changes: 101 additions & 0 deletions Hawk/internal/functions/AuditLog_Updated.csv
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be in the repo, this is an output file from hawk being ran.

Large diffs are not rendered by default.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be in the repo, this is an output file from hawk being ran.

Empty file.
71 changes: 41 additions & 30 deletions Hawk/internal/functions/Initialize-HawkGlobalObject.ps1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Line 81 and line 348 has a random line of text that is not code, causing the script to error out when running Start-HawkTenantInvestigation
    o bugfix/151-ensure-all-scripts-use-utc-time-instead-of-local-time

Before submitting a merge request, the code needs to be ran to makes sure your changes to the code base do not introduce errors like this.

image

Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@
param([string]$RootPath)

# Create a folder ID based on date
[string]$TenantName = (Get-MGDomain | Where-Object { $_.isDefault }).ID
[string]$FolderID = "Hawk_" + $TenantName.Substring(0, $TenantName.IndexOf('.')) + "_" + (Get-Date -UFormat %Y%m%d_%H%M).tostring()
bugfix/151-ensure-all-scripts-use-utc-time-instead-of-local-time
[string]$TenantName = (Get-MGDomain | Where-Object {$_.isDefault}).ID
[string]$FolderID = "Hawk_" + $TenantName.Substring(0, $TenantName.IndexOf('.')) + "_" + (Get-Date).ToUniversalTime().ToString("yyyyMMdd_HHmm")



# Add that ID to the given path
$FullOutputPath = Join-Path $RootPath $FolderID
Expand Down Expand Up @@ -178,7 +181,8 @@
switch ($result) {
0 {
Write-Information "`n"
Return ("Agreed " + (Get-Date)).ToString()
Return ("Agreed " + (Get-Date).ToUniversalTime().ToString())

}
1 {
Write-Information "Aborting Cmdlet"
Expand Down Expand Up @@ -230,7 +234,8 @@
### Validating EULA ###
if ($IAgreeToTheEula) {
# Customer has accepted the EULA on the command line
[string]$Eula = ("Agreed " + (Get-Date))
[string]$Eula = "Agreed " + (Get-Date).ToUniversalTime().ToString()

}
else {
[string]$Eula = Get-Eula
Expand Down Expand Up @@ -266,23 +271,26 @@

# Calculate our startdate setting it to midnight
Write-Information ("Calculating Start Date from current date minus " + $StartRead + " days.")
[DateTime]$StartDate = ((Get-Date).AddDays(-$StartRead)).Date
[DateTime]$StartDate = ((Get-Date).ToUniversalTime().AddDays(-$StartRead)).Date

Write-Information ("Setting StartDate by Calculation to " + $StartDate + "`n")
}
elseif (!($null -eq ($StartRead -as [DateTime]))) {
#### DATE TIME Provided ####

# Convert the input to a date time object
[DateTime]$StartDate = (Get-Date $StartRead).Date
[DateTime]$StartDate = (Get-Date $StartRead).ToUniversalTime().Date


# Test to make sure the date time is > 90 and < today
if ($StartDate -ge ((Get-date).AddDays(-90).Date) -and ($StartDate -le (Get-Date).Date)) {
if ($StartDate -ge ((Get-Date).ToUniversalTime().AddDays(-90)).Date -and $StartDate -le (Get-Date).ToUniversalTime().Date){
#Valid Date do nothing
}
else {
Write-Information ("Date provided beyond acceptable range of 90 days.")
Write-Information ("Setting date to default of Today - 90 days.")
[DateTime]$StartDate = ((Get-Date).AddDays(-90)).Date
[DateTime]$StartDate = (Get-Date).ToUniversalTime().AddDays(-90).Date

}

Write-Information ("Setting StartDate by Date to " + $StartDate + "`n")
Expand All @@ -304,13 +312,15 @@
# if we have a null entry (just hit enter) then set startread to the default of 90
if ([string]::IsNullOrEmpty($EndRead)) {
Write-Information ("Setting End Date to Today")
[DateTime]$EndDate = ((Get-Date).AddDays(1)).Date
[DateTime]$EndDate = ((Get-Date).ToUniversalTime().AddDays(1)).Date

}
else {
# Calculate our startdate setting it to midnight
Write-Information ("Calculating End Date from current date minus " + $EndRead + " days.")
# Subtract 1 from the EndRead entry so that we get one day less for the purpose of how searching works with times
[DateTime]$EndDate = ((Get-Date).AddDays( - ($EndRead - 1))).Date
[DateTime]$EndDate = (Get-Date).ToUniversalTime().AddDays(-($EndRead - 1)).Date

}

# Validate that the start date is further back in time than the end date
Expand All @@ -325,28 +335,26 @@
#### DATE TIME Provided ####

# Convert the input to a date time object
[DateTime]$EndDate = ((Get-Date $EndRead).AddDays(1)).Date
[DateTime]$EndDate = (Get-Date $EndRead).ToUniversalTime().AddDays(1).Date


# Test to make sure the end date is newer than the start date
if ($StartDate -gt $EndDate) {
Write-Information "EndDate Selected was older than start date."
Write-Information "Setting EndDate to today."
[DateTime]$EndDate = ((Get-Date).AddDays(1)).Date
}
elseif ($EndDate -gt (get-Date).AddDays(2)) {
Write-Information "EndDate to Far in the furture."
Write-Information "Setting EndDate to Today."
[DateTime]$EndDate = ((Get-Date).AddDays(1)).Date
}
[DateTime]$EndDate = (Get-Date).ToUniversalTime().AddDays(1).Date

Write-Information ("Setting EndDate by Date to " + $EndDate + "`n")
}
bugfix/151-ensure-all-scripts-use-utc-time-instead-of-local-time
}

else {
Write-Error "Invalid date information provided. Could not determine if this was a date or an integer." -ErrorAction Stop
Write-Error "Invalid date information provided. Could not determine if this was a date or an integer." -ErrorAction Stop
}
}



# Determine if we have access to a P1 or P2 Azure Ad License
# EMS SKU contains Azure P1 as part of the sku
# This uses Graph instead of MSOL
Expand All @@ -367,16 +375,19 @@
Set-PSFConfig -Module 'Hawk' -Name 'FilePath' -Value $OutputPath -PassThru | Register-PSFConfig
}

#TODO: Discard below once migration to configuration is completed
$Output = [PSCustomObject]@{
FilePath = $OutputPath
DaysToLookBack = $Days
StartDate = $StartDate
EndDate = $EndDate
AdvancedAzureLicense = $AdvancedAzureLicense
WhenCreated = (Get-Date -Format g)
EULA = $Eula
}

#TODO: Discard below once migration to configuration is completed
$Output = [PSCustomObject]@{
FilePath = $OutputPath
DaysToLookBack = $Days
StartDate = $StartDate
EndDate = $EndDate
AdvancedAzureLicense = $AdvancedAzureLicense
WhenCreated = (Get-Date).ToUniversalTime().ToString("g")
EULA = $Eula
}



# Create the script hawk variable
Write-Information "Setting up Script Hawk environment variable`n"
Expand Down
3 changes: 2 additions & 1 deletion Hawk/internal/functions/Out-LogFile.ps1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be fine. Have you tested running this to make sure it works as intended?

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ Function Out-LogFile {
$LogOutput = $true

# Get the current date
[string]$date = Get-Date -Format G
[string]$date = (Get-Date).ToUniversalTime().ToString("G")


# Deal with each switch and what log string it should put out and if any special output

Expand Down
34 changes: 34 additions & 0 deletions Hawk/internal/scripts/coverage.xml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be in the repo, this is an output file from hawk being ran.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE report PUBLIC "-//JACOCO//DTD Report 1.1//EN" "report.dtd"[]>
<report name="Pester (12/12/2024 00:57:03)">
<sessioninfo id="this" start="1733964927641" dump="1733965023306" />
<package name="scripts">
<class name="scripts/license" sourcefilename="license.ps1">
<method name="&lt;script&gt;" desc="()" line="1">
<counter type="INSTRUCTION" missed="2" covered="0" />
<counter type="LINE" missed="2" covered="0" />
<counter type="METHOD" missed="1" covered="0" />
</method>
<counter type="INSTRUCTION" missed="2" covered="0" />
<counter type="LINE" missed="2" covered="0" />
<counter type="METHOD" missed="1" covered="0" />
<counter type="CLASS" missed="1" covered="0" />
</class>
<sourcefile name="license.ps1">
<line nr="1" mi="1" ci="0" mb="0" cb="0" />
<line nr="3" mi="1" ci="0" mb="0" cb="0" />
<counter type="INSTRUCTION" missed="2" covered="0" />
<counter type="LINE" missed="2" covered="0" />
<counter type="METHOD" missed="1" covered="0" />
<counter type="CLASS" missed="1" covered="0" />
</sourcefile>
<counter type="INSTRUCTION" missed="2" covered="0" />
<counter type="LINE" missed="2" covered="0" />
<counter type="METHOD" missed="1" covered="0" />
<counter type="CLASS" missed="1" covered="0" />
</package>
<counter type="INSTRUCTION" missed="2" covered="0" />
<counter type="LINE" missed="2" covered="0" />
<counter type="METHOD" missed="1" covered="0" />
<counter type="CLASS" missed="1" covered="0" />
</report>
1 change: 1 addition & 0 deletions Resolving IP Locations
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be in the repo, this is an output file from hawk being ran.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ÿþ
Binary file added documentation/bugfix_151_report.docx
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be in the repo, this is an output file from hawk being ran.

Binary file not shown.
Binary file added logs/Hawk.log
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be in the repo, this is an output file from hawk being ran.

Binary file not shown.
Binary file added logs/_Investigate.txt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be in the repo, this is an output file from hawk being ran.

Binary file not shown.
Loading