Skip to content

Commit

Permalink
Fix casing and improve readability in PowerShell scripts (#280)
Browse files Browse the repository at this point in the history
Corrected method names and parameters for consistency with PowerShell naming conventions. Updated logging functions for consistent casing and improved formatting. Enhanced code clarity and maintainability through minor adjustments and clearer comments.

Co-authored-by: Antonio Santana <[email protected]>
  • Loading branch information
Sntai20 and Antonio Santana authored Mar 3, 2025
1 parent aa23e68 commit 1cbf0d6
Show file tree
Hide file tree
Showing 30 changed files with 64 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Hawk/functions/General/Update-HawkModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
else
{
Out-LogFile "Checking for latest version online" -Action
$onlineversion = Find-Module -name Hawk -erroraction silentlycontinue
$onlineversion = Find-Module -Name Hawk -ErrorAction silentlycontinue
$Localversion = (Get-Module Hawk | Sort-Object -Property Version -Descending)[0]
Out-LogFile ("Found Version " + $onlineversion.version + " Online") -Information

Expand Down
2 changes: 1 addition & 1 deletion Hawk/functions/Tenant/Search-HawkTenantActivityByIP.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
{

# Expand out the Data and convert from JSON
[array]$ipeventsexpanded = $ipevents | Select-object -ExpandProperty AuditData | ConvertFrom-Json
[array]$ipeventsexpanded = $ipevents | Select-Object -ExpandProperty AuditData | ConvertFrom-Json
Out-LogFile ("Found " + $ipeventsexpanded.count + " related to provided IP" ) -Information
$ipeventsexpanded | Out-MultipleFileType -FilePrefix "All_Events" -csv -json -User $DirectoryName

Expand Down
2 changes: 1 addition & 1 deletion Hawk/functions/User/Get-HawkUserExchangeSearchQuery.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
$ExchangeSearchesSimple = $ExchangeSearches | Get-SimpleUnifiedAuditLog

#Export both raw and simplistic views to specified user's folder
$ExchangeSearches | Select-Object -ExpandProperty AuditData | Convertfrom-Json | Out-MultipleFileType -FilePrefix "ExchangeSearchQueries_$User" -User $User -csv -json
$ExchangeSearches | Select-Object -ExpandProperty AuditData | ConvertFrom-Json | Out-MultipleFileType -FilePrefix "ExchangeSearchQueries_$User" -User $User -csv -json
$ExchangeSearchesSimple | Out-MultipleFileType -FilePrefix "Simple_ExchangeSearchQueries_$User" -User $User -csv -json
}
else
Expand Down
2 changes: 1 addition & 1 deletion Hawk/functions/User/Get-HawkUserMailItemsAccessed.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
$MailboxItemsAccessedSimple = $MailboxItemsAccessed | Get-SimpleUnifiedAuditLog

#Export both raw and simplistic views to specified user's folder
$MailboxItemsAccessed | Select-Object -ExpandProperty AuditData | Convertfrom-Json | Out-MultipleFileType -FilePrefix "MailItemsAccessed_$User" -User $User -csv -json
$MailboxItemsAccessed | Select-Object -ExpandProperty AuditData | ConvertFrom-Json | Out-MultipleFileType -FilePrefix "MailItemsAccessed_$User" -User $User -csv -json
$MailboxItemsAccessedSimple | Out-MultipleFileType -FilePrefix "Simple_MailItemsAccessed_$User" -User $User -csv -json
}
else
Expand Down
2 changes: 1 addition & 1 deletion Hawk/functions/User/Get-HawkUserMailSendActivity.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
$ExchangeSendsSimple = $ExchangeSends | Get-SimpleUnifiedAuditLog

#Export both raw and simplistic views to specified user's folder
$ExchangeSends | Select-Object -ExpandProperty AuditData | Convertfrom-Json | Out-MultipleFileType -FilePrefix "SendActivity_$User" -User $User -csv -json
$ExchangeSends | Select-Object -ExpandProperty AuditData | ConvertFrom-Json | Out-MultipleFileType -FilePrefix "SendActivity_$User" -User $User -csv -json
$ExchangeSendsSimple | Out-MultipleFileType -FilePrefix "Simple_SendActivity_$User" -User $User -csv -json
}
else
Expand Down
8 changes: 4 additions & 4 deletions Hawk/functions/User/Get-HawkUserPWNCheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
#https://haveibeenpwned.com/API/v3#ResponseCodes contains the response codes for the API
try
{
$Result = Invoke-WebRequest -Uri $InvokeURL -Headers $headers -userAgent 'Hawk' -ErrorAction Stop
$Result = Invoke-WebRequest -Uri $InvokeURL -Headers $headers -UserAgent 'Hawk' -ErrorAction Stop
}
catch
{
Expand All @@ -81,17 +81,17 @@
{
NotFound
{
write-host "Email Provided Not Found in Pwned Database"
Write-Host "Email Provided Not Found in Pwned Database"
return
}
Unauthorized
{
write-host "Unauthorised Access - API key provided is not valid or has expired"
Write-Host "Unauthorised Access - API key provided is not valid or has expired"
return
}
Default
{
write-host $ErrorMessage
Write-Host $ErrorMessage
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion Hawk/functions/User/Get-HawkUserSharePointSearchQuery.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
$SharePointSearchesSimple = $SharePointSearches | Get-SimpleUnifiedAuditLog

#Export both raw and simplistic views to specified user's folder
$SharePointSearches | Select-Object -ExpandProperty AuditData | Convertfrom-Json | Out-MultipleFileType -FilePrefix "SharePointSearches_$User" -User $User -csv -json
$SharePointSearches | Select-Object -ExpandProperty AuditData | ConvertFrom-Json | Out-MultipleFileType -FilePrefix "SharePointSearches_$User" -User $User -csv -json
$SharePointSearchesSimple | Out-MultipleFileType -FilePrefix "Simple_SharePointSearches_$User" -User $User -csv -json
}
else
Expand Down
2 changes: 1 addition & 1 deletion Hawk/internal/WorkInProgress/Get-HawkTenantInboxRule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
}

# Get the exo PS session
$exopssession = get-pssession | Where-Object { ($_.ConfigurationName -eq 'Microsoft.Exchange') -and ($_.State -eq 'Opened') }
$exopssession = Get-PSSession | Where-Object { ($_.ConfigurationName -eq 'Microsoft.Exchange') -and ($_.State -eq 'Opened') }

# Gather all of the mailboxes
Out-LogFile "Getting all Mailboxes" -Action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
{
$MailboxItemsAccessed = Get-AllUnifiedAuditLogEntry -UnifiedSearch ("Search-UnifiedAuditLog -Operations 'MailItemsAccessed' -FreeText $ApplicationID ")

$MailboxItemsAccessed | Select-Object -ExpandProperty AuditData | Convertfrom-Json | Out-MultipleFileType -FilePrefix "MailItemsAccessed" -csv -json
$MailboxItemsAccessed | Select-Object -ExpandProperty AuditData | ConvertFrom-Json | Out-MultipleFileType -FilePrefix "MailItemsAccessed" -csv -json
}#End Process

END
Expand Down
2 changes: 1 addition & 1 deletion Hawk/internal/configurations/configuration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $handler = {
$paramSetPSFLoggingProvider = @{
Name = 'logfile'
InstanceName = 'Hawk'
FilePath = Join-Path -path $args[0] -ChildPath '%date%_logs.csv'
FilePath = Join-Path -Path $args[0] -ChildPath '%date%_logs.csv'
TimeFormat = 'yyyy-MM-dd HH:mm:ss.fff'
IncludeModules = 'Hawk'
UTC = $true
Expand Down
2 changes: 1 addition & 1 deletion Hawk/internal/functions/Add-HawkAppData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Function Add-HawkAppData
Out-LogFile ("Adding " + $value + " to " + $Name + " in HawkAppData") -Action

# Test if our HawkAppData variable exists
if ([bool](get-variable HawkAppData -ErrorAction SilentlyContinue))
if ([bool](Get-Variable HawkAppData -ErrorAction SilentlyContinue))
{
$global:HawkAppData | Add-Member -MemberType NoteProperty -Name $Name -Value $Value
}
Expand Down
2 changes: 1 addition & 1 deletion Hawk/internal/functions/Compress-HawkData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Function Compress-HawkData
#Out-LogFile ("Found " + $allfiles.count + " files to add to zip")

# create the zip file name
[string]$zipname = "Hawk_" + (Split-path $Hawk.filepath -Leaf) + ".zip"
[string]$zipname = "Hawk_" + (Split-Path $Hawk.filepath -Leaf) + ".zip"
[string]$zipfullpath = Join-Path $env:TEMP $zipname

Out-LogFile ("Creating temporary zip file " + $zipfullpath)
Expand Down
6 changes: 3 additions & 3 deletions Hawk/internal/functions/Convert-ReportToHTML.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ Function Convert-ReportToHTML
begin
{
# Make sure that the files are there
if (!(test-path $Xml))
if (!(Test-Path $Xml))
{
Write-Error "XML File not found for conversion" -ErrorAction Stop
}
if (!(test-path $Xsl))
if (!(Test-Path $Xsl))
{
Write-Error "XSL File not found for Conversion" -ErrorAction Stop
}
Expand All @@ -43,7 +43,7 @@ Function Convert-ReportToHTML
process
{
# Create the output file name
$OutputFile = Join-Path (Split-path $xml) ((split-path $xml -Leaf).split(".")[0] + ".html")
$OutputFile = Join-Path (Split-Path $xml) ((Split-Path $xml -Leaf).split(".")[0] + ".html")

# Run the transform on the XML and produce the HTML
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform
Expand Down
2 changes: 1 addition & 1 deletion Hawk/internal/functions/Get-AllUnifiedAuditLogEntry.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}

# build our search command to execute
$cmd = $UnifiedSearch + " -StartDate `'" + (get-date ($StartDate) -UFormat %m/%d/%Y) + "`' -EndDate `'" + (get-date ($endDate) -UFormat %m/%d/%Y) + "`' -SessionCommand ReturnLargeSet -resultsize 5000 -sessionid " + (Get-Date -UFormat %H%M%S)
$cmd = $UnifiedSearch + " -StartDate `'" + (Get-Date ($StartDate) -UFormat %m/%d/%Y) + "`' -EndDate `'" + (Get-Date ($endDate) -UFormat %m/%d/%Y) + "`' -SessionCommand ReturnLargeSet -resultsize 5000 -sessionid " + (Get-Date -UFormat %H%M%S)
Out-LogFile ("Running Unified Audit Log Search") -Action
Out-Logfile $cmd -NoDisplay

Expand Down
6 changes: 3 additions & 3 deletions Hawk/internal/functions/Get-IPGeolocation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Function Get-IPGeolocation
)

# If we don't have a HawkAppData variable then we need to read it in
if (!([bool](get-variable HawkAppData -erroraction silentlycontinue)))
if (!([bool](Get-Variable HawkAppData -ErrorAction silentlycontinue)))
{
Read-HawkAppData
}
Expand Down Expand Up @@ -54,7 +54,7 @@ Function Get-IPGeolocation
}
elseif ($IPAddress -eq "<null>")
{
write-Verbose ("Null IP Provided: " + $IPAddress)
Write-Verbose ("Null IP Provided: " + $IPAddress)
$hash = @{
IP = $IPAddress
CountryName = "NULL IP"
Expand All @@ -73,7 +73,7 @@ Function Get-IPGeolocation

# Return Data from web
$Error.Clear()
$geoip = Invoke-RestMethod -Method Get -URI $resource -ErrorAction SilentlyContinue
$geoip = Invoke-RestMethod -Method Get -Uri $resource -ErrorAction SilentlyContinue

if (($Error.Count -gt 0) -or ($null -eq $geoip.type))
{
Expand Down
8 changes: 4 additions & 4 deletions Hawk/internal/functions/Import-AzureAuthenticationLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Function Import-AzureAuthenticationLog
$processedentry = New-Object -TypeName PSobject

# Look at each member of the entry ... we want to process each in turn and add them to a new object
foreach ($member in ($entry | get-member -MemberType NoteProperty))
foreach ($member in ($entry | Get-Member -MemberType NoteProperty))
{

# Identity unique properties and add to property list of base object if not present
Expand All @@ -67,7 +67,7 @@ Function Import-AzureAuthenticationLog
if ($baseproperties -contains $object.name) { }
else
{
$baseproperties.add($object.name) | out-null
$baseproperties.add($object.name) | Out-Null
}

# For some entries a property can appear in ExtendedProperties and as a normal property
Expand Down Expand Up @@ -137,7 +137,7 @@ Function Import-AzureAuthenticationLog
}
Creationtime
{
$processedentry | Add-Member -MemberType NoteProperty -Name CreationTime -value (get-date $entry.Creationtime -format g)
$processedentry | Add-Member -MemberType NoteProperty -Name CreationTime -Value (Get-Date $entry.Creationtime -Format g)
}
Default
{
Expand Down Expand Up @@ -172,7 +172,7 @@ Function Import-AzureAuthenticationLog
{
switch ($propertyname)
{
CreationTime { $baseobject | Add-Member -MemberType NoteProperty -Name $propertyname -Value (get-date 01/01/1900 -format g) }
CreationTime { $baseobject | Add-Member -MemberType NoteProperty -Name $propertyname -Value (Get-Date 01/01/1900 -Format g) }
Default { $baseobject | Add-Member -MemberType NoteProperty -Name $propertyname -Value "Base" }
}
}
Expand Down
6 changes: 3 additions & 3 deletions Hawk/internal/functions/Out-HawkAppData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
#>
Function Out-HawkAppData
{
$HawkAppdataPath = join-path $env:LOCALAPPDATA "Hawk\Hawk.json"
$HawkAppdataFolder = join-path $env:LOCALAPPDATA "Hawk"
$HawkAppdataPath = Join-Path $env:LOCALAPPDATA "Hawk\Hawk.json"
$HawkAppdataFolder = Join-Path $env:LOCALAPPDATA "Hawk"

# test if the folder exists
if (test-path $HawkAppdataFolder) { }
if (Test-Path $HawkAppdataFolder) { }
# if it doesn't we need to create it
else
{
Expand Down
6 changes: 3 additions & 3 deletions Hawk/internal/functions/Out-LogFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
[switch]$NoNewLine
)

Write-PSFMessage -Message $string -ModuleName Hawk -FunctionName (Get-PSCallstack)[1].FunctionName
Write-PSFMessage -Message $string -ModuleName Hawk -FunctionName (Get-PSCallStack)[1].FunctionName

# Make sure we have the Hawk Global Object
if ([string]::IsNullOrEmpty($Hawk.FilePath))
Expand All @@ -134,7 +134,7 @@
}

# Get our log file path
$LogFile = Join-path $Hawk.FilePath "Hawk.log"
$LogFile = Join-Path $Hawk.FilePath "Hawk.log"
$ScreenOutput = -not $NoDisplay
$LogOutput = $true

Expand Down Expand Up @@ -201,7 +201,7 @@
{
if ($NoNewLine)
{
Write-Host $logstring -InformationAction Continue -NoNewLine
Write-Host $logstring -InformationAction Continue -NoNewline
}
else
{
Expand Down
12 changes: 6 additions & 6 deletions Hawk/internal/functions/Out-MultipleFileType.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ Function Out-MultipleFileType
# Set the output path
if ([string]::IsNullOrEmpty($User))
{
$path = join-path $Hawk.filepath "\Tenant"
$path = Join-Path $Hawk.filepath "\Tenant"
# Test the path if it is there do nothing otherwise create it
if (test-path $path) { }
if (Test-Path $path) { }
else
{
Out-LogFile ("Making output directory for Tenant " + $Path) -Action
Expand All @@ -72,15 +72,15 @@ Function Out-MultipleFileType
}
else
{
$path = join-path $Hawk.filepath $user
$path = Join-Path $Hawk.filepath $user

# Set a bool so we know this is a user output
[bool]$UserOutput = $true
# Build short name of user so that it is easier to read
[string]$ShortUser = ($User.split('@'))[0]

# Test the path if it is there do nothing otherwise create it
if (test-path $path) { }
if (Test-Path $path) { }
else
{
Out-LogFile ("Making output directory for user " + $Path) -Action
Expand Down Expand Up @@ -111,8 +111,8 @@ Function Out-MultipleFileType
if ($xml -eq $true)
{
# lets put the xml files in a seperate directory to not clutter things up
$xmlpath = Join-path $Path XML
if (Test-path $xmlPath) { }
$xmlpath = Join-Path $Path XML
if (Test-Path $xmlPath) { }
else
{
Out-LogFile ("Making output directory for xml files " + $xmlPath) -Action
Expand Down
12 changes: 6 additions & 6 deletions Hawk/internal/functions/Out-Report.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
# Set our output path
# Single report file for all outputs user/tenant/etc.
# This might change in the future???
$reportpath = Join-path $hawk.filepath report.xml
$reportpath = Join-Path $hawk.filepath report.xml

# Switch statement to handle the state to color mapping
switch ($State)
Expand All @@ -55,14 +55,14 @@
}

# Check if we have our XSL file in the output directory
$xslpath = Join-path $hawk.filepath Report.xsl
$xslpath = Join-Path $hawk.filepath Report.xsl

if (Test-Path $xslpath ) { }
else
{
# Copy the XSL file into the current output path
$sourcepath = join-path (split-path (Get-Module Hawk).path) report.xsl
if (test-path $sourcepath)
$sourcepath = Join-Path (Split-Path (Get-Module Hawk).path) report.xsl
if (Test-Path $sourcepath)
{
Copy-Item -Path $sourcepath -Destination $hawk.filepath
}
Expand All @@ -75,10 +75,10 @@

# See if we have already created a report file
# If so we need to import it
if (Test-path $reportpath)
if (Test-Path $reportpath)
{
$reportxml = $null
[xml]$reportxml = get-content $reportpath
[xml]$reportxml = Get-Content $reportpath
}
# Since we have NOTHING we will create a new XML and just add / save / and exit
else
Expand Down
4 changes: 2 additions & 2 deletions Hawk/internal/functions/Read-HawkAppData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
#>
Function Read-HawkAppData
{
$HawkAppdataPath = join-path $env:LOCALAPPDATA "Hawk\Hawk.json"
$HawkAppdataPath = Join-Path $env:LOCALAPPDATA "Hawk\Hawk.json"

# check to see if our xml file is there
if (test-path $HawkAppdataPath)
if (Test-Path $HawkAppdataPath)
{
Out-LogFile ("Reading file " + $HawkAppdataPath) -Action
$global:HawkAppData = ConvertFrom-Json -InputObject ([string](Get-Content $HawkAppdataPath))
Expand Down
2 changes: 1 addition & 1 deletion Hawk/internal/functions/Start-SleepWithProgress.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Function Start-SleepWithProgress
Write-Progress -Activity "Sleeping" -CurrentOperation "$Timeleft More Seconds" -PercentComplete (($i / $sleeptime) * 100)

# Sleep 1 second
start-sleep 1
Start-Sleep 1
}

Write-Progress -Completed -Activity "Sleeping"
Expand Down
4 changes: 2 additions & 2 deletions Hawk/internal/functions/Test-MicrosoftIP.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Function Test-MicrosoftIP
Out-Logfile "Building MSFTIPList" -Action

# Load our networking dll pulled from https://github.com/lduchosal/ipnetwork
[string]$dll = join-path (Split-path (((get-module Hawk)[0]).path) -Parent) "\bin\System.Net.IPNetwork.dll"
[string]$dll = Join-Path (Split-Path (((Get-Module Hawk)[0]).path) -Parent) "\bin\System.Net.IPNetwork.dll"

$Error.Clear()
Out-LogFile ("Loading Networking functions from " + $dll) -Action
Expand All @@ -48,7 +48,7 @@ Function Test-MicrosoftIP

$Error.clear()

$MSFTJSON = (Invoke-WebRequest -uri ("https://endpoints.office.com/endpoints/Worldwide?ClientRequestId=" + (new-guid).ToString())).content | ConvertFrom-Json
$MSFTJSON = (Invoke-WebRequest -Uri ("https://endpoints.office.com/endpoints/Worldwide?ClientRequestId=" + (New-Guid).ToString())).content | ConvertFrom-Json

if ($Error.Count -gt 0)
{
Expand Down
2 changes: 1 addition & 1 deletion Hawk/internal/functions/Test-OperationEnabled.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
)

# Verify the provided User has the specified Operation enabled
$TestResult = Get-Mailbox -Identity $User | Where-Object -Property AuditOwner -eq $Operation
$TestResult = Get-Mailbox -Identity $User | Where-Object -Property AuditOwner -EQ $Operation

if ($null -eq $TestResult)
{
Expand Down
Loading

0 comments on commit 1cbf0d6

Please sign in to comment.