Wanted to build an Azure resources inventory datamart using

Anandsbr 0 Reputation points
2024-04-18T17:37:04.51+00:00

Hell All,

I have a requirement to call an azure API via power shell or python (will be scheduled to run) to build an inventory (resources, resource ids, subscription id, DataMart and create a report off of them.

I have the the credentials (client Id, Secret ID, Tenant ID) that are needed to invoke graph resources via KQL but looks like modules need to be installed on the target servers which is an impediment. Also not sure if scope is wrong.

Are there any other method to easily achieve this (without having to install all these az modules)?

When i run the below code, I get Search-AzGraph is unrecognized (not installed)

My current code is

$tenant = << tenant ID>>
$appid = << app ID>>
$secret = << Secret ID>>
$body = @{
    Grant_Type = "client_credentials"
    Scope = "https://graph.microsoft.com/.default"
    Client_Id = $appid
    Client_Secret = $secret
}
$connection = Invoke-RestMethod -Uri https://login.microsoftonline.com/$tenant/oauth2/v2.0/token -Method Post -Body $body
#Write-Host $connection.access_token
Connect-MgGraph -AccessToken ($connection.access_token  | ConvertTo-SecureString -AsPlainText -Force)
$KustoQuery = "
resources
| where name starts with 'Network'
"
$result = Search-AzGraph -Query $KustoQuery
$result | select name
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,616 questions
0 comments No comments
{count} votes