Feature: Add IP Geolocation Lookup to Get-HawkUserEntraIDSignInLog Function
What problem would this feature solve?
Currently, Get-HawkUserEntraIDSignInLog retrieves sign-in logs from Microsoft Entra ID but does not provide IP geolocation information for the sign-in events. This makes it harder for security analysts to:
- Quickly identify suspicious login locations
- Detect potential geographic-based authentication anomalies
- Compare sign-in patterns across different geographical regions
- Group and analyze access patterns by country/region
The existing Get-HawkUserUALSignInLog function already provides this capability through IP geolocation lookups, but this functionality needs to be extended to the newer Entra ID sign-in log retrieval function to maintain feature parity and provide consistent analysis capabilities across both methods.
Proposed Solution
Enhance Get-HawkUserEntraIDSignInLog to:
- Add a
-ResolveIPLocationsswitch parameter to matchGet-HawkUserUALSignInLogfunctionality. - Utilize the existing
Get-IPGeolocationinternal function to lookup location data for each unique IP address. - Add location data (
country,region,city) to the output objects. - Mark Microsoft-owned IP addresses using the
Test-MicrosoftIPfunction. - Export the enhanced data in both CSV and JSON formats with the additional geolocation fields.
The function should maintain the existing error handling and output formatting while adding the new geolocation capabilities.
Technical Requirements
-
Add
ResolveIPLocationsswitch parameter -
Reuse existing internal functions:
Get-IPGeolocationfor location lookups.Test-MicrosoftIPfor Microsoft IP detection.IPlocationCacheglobal variable for caching.
-
Add new properties to output objects:
CountryNameRegionCodeRegionNameCityKnownMicrosoftIP
-
Handle
null/invalid IP addresses gracefully. -
Maintain existing performance optimization techniques like IP caching.
-
Ensure proper error handling for geolocation service failures.
Implementation Approach
-
Update function parameter block to include
ResolveIPLocationsswitch. ``` -
Reuse existing caching mechanism to prevent duplicate lookups.
-
Add documentation for the new parameter and functionality.
-
Update output formatting to include new location fields.
Acceptance Criteria
- Function accepts
-ResolveIPLocationsswitch parameter. - IP addresses are correctly resolved to geographic locations.
- Microsoft IPs are properly identified.
- Location data is correctly added to output objects.
- IP location caching works as expected.
- Performance remains acceptable with geolocation enabled.
- Output files contain all geolocation fields.
- Error handling properly manages geolocation service failures.
- Documentation is updated to reflect new functionality.
- Unit tests cover new geolocation functionality.