Forum Discussion

zac's avatar
zac
Copper Contributor
Nov 29, 2024
Solved

Microsoft Graph Sign in Log Script

Hi all,   I'm trying to create a script that will check sign ins based on the location. How ever the location always appears as 'Microsoft.Graph.PowerShell.Models.MicrosoftGraphSignInLocation'. ...
  • dremba's avatar
    Dec 16, 2024

    Hi Zac,

    you can display the location with the other properties by adding it as an expression. You call the respective property with Location.<property>. This works with all properties where the value is an object, i.e. starts with Microsoft.Graph.PowerShell.Models.

    Example:
    Get-MgAuditLogSignIn | Select-Object -First 1 -Property CreatedDateTime, AppDisplayName, ClientAppUsed, IPAddress, @{Name=“City”;Expression={$_.Location.City}}, @{Name=“Country/Region”;Expression={$_. Location.CountryOrRegion}}, @{Name=“State”;Expression={$_.Location.State}}, @{Name=“ErrorCode”;Expression={$_.Status.ErrorCode}}, @{Name=“FailureReason”;Expression={$_.Status.FailureReason}}

    To know which properties exist for an object, you can display the members of the object as follows:

    $signIn = Get-MgAuditLogSignIn | Select-Object -First 1
    $signIn.Location | Get-Member

    Among other things, the properties with the MemberType property are displayed here.

    I hope this is what you meant.

Resources