Skip to content

Invoke-FalconIdentityGraph - example of variable substitution #457

Closed

Description

@hkelley

Description of your question
Could you please provide an example of how to use variable substitution in

Invoke-FalconIdentityGraph

https://github.com/CrowdStrike/psfalcon/wiki/Invoke-FalconIdentityGraph

The wiki mentions the capability but I don't see any example of how to format/mark the variables in the graph query.

I'm trying to use your variable substitution instead of entityIds:["{0}"] and -f $entityUuid in the snippet below:

$fql = "product:'idp'+name:['ExcessiveDailyUsage','ExcessiveTargetDailyUsage']"

foreach($alert in Get-FalconAlert -Filter $fql -Limit 10 -Detailed) {

  $alertId = ($alert.id -split ':')[2]
  $entityUuid = $alert.source_account_object_guid

  $query = @"
  query GetIncidentAlertsForUser {{
    incidents(
      first: 10,
      entityQuery:{{
        entityIds:["{0}"]
      }}
      types:[POTENTIAL_RISKY_ACTIVITY],     
      sortKey: END_TIME,
      sortOrder: DESCENDING
      ) {{
      nodes {{
        incidentId
        type      
        startTime
        endTime
        compromisedEntities {{
          primaryDisplayName
          type
        }}
        alertEvents {{
          alertId
          eventId
          patternId
          alertType
          eventLabel
          entities {{
            primaryDisplayName
          }}
          sourceEntity{{
            entityId
            primaryDisplayName
          }}        
          relatedEvents(first: 1000) {{
            nodes {{
              timestamp
              ... on TimelineUserOnEndpointActivityEvent {{
                userEntity {{
                  primaryDisplayName
                }}
                endpointEntity {{
                  primaryDisplayName
                  entityId 
                }}
                targetEntity {{
                  primaryDisplayName
                  entityId              
                }}
              }}
            }}
          }}
        }}
      }}
    }}
  }}
"@ -f $entityUuid

Activity

  1. added
    question
    on Mar 21, 2025
  2. self-assigned this
    on Mar 21, 2025
  3. bk-cs commented on Mar 21, 2025

    @bk-cs
    Contributor

    -f only works in single quote strings, but you can't use that because of the use of brackets in the GraphQL query. You can replace {0} instead:

    $query = @'
      query GetIncidentAlertsForUser {
        incidents(
          first: 10,
          entityQuery:{
            entityIds:["{0}"]
          }
          types:[POTENTIAL_RISKY_ACTIVITY],     
          sortKey: END_TIME,
          sortOrder: DESCENDING
          ) {
          nodes {
            incidentId
            type      
            startTime
            endTime
            compromisedEntities {
              primaryDisplayName
              type
            }
            alertEvents {
              alertId
              eventId
              patternId
              alertType
              eventLabel
              entities {
                primaryDisplayName
              }
              sourceEntity{
                entityId
                primaryDisplayName
              }        
              relatedEvents(first: 1000) {
                nodes {
                  timestamp
                  ... on TimelineUserOnEndpointActivityEvent {
                    userEntity {
                      primaryDisplayName
                    }
                    endpointEntity {
                      primaryDisplayName
                      entityId 
                    }
                    targetEntity {
                      primaryDisplayName
                      entityId              
                    }
                  }
                }
              }
            }
          }
        }
      }
    '@
    $query = $query -replace '\{0\}',$entityUuid
    
  4. changed the title [-]Invoke-FalconIdentityGraph - example of variable substitution[/-] [+]`Invoke-FalconIdentityGraph` - example of variable substitution[/+] on Mar 21, 2025
  5. locked and limited conversation to collaborators on Mar 21, 2025
  6. converted this issue into a discussion #458 on Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

question

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions