Forum Discussion
dafo43
Jun 13, 2020Copper Contributor
Graph API and Powershell
I'm looking to use the Graph API to get some Teams stats using PowerShell - https://docs.microsoft.com/en-us/graph/api/reportroot-getteamsuseractivitycounts?view=graph-rest-1.0 . The content seems to return values but just a long list of numbers, no rows or columns, and there is nothing to identify which Team the stats belong to.
Are there any examples of this working with PowerShell?
$ADALpath = 'C:\Program Files\WindowsPowerShell\Modules\AzureADPreview\2.0.2.89\Microsoft.IdentityModel.Clients.ActiveDirectory.dll'
$tenantID = "xxx"
$appID = "xxx"
$client_secret = "xxx"
try { Add-Type -Path $ADALpath -ErrorAction Stop }
catch { Write-Error "Unable to load ADAL binaries, make sure you are using the correct path!" -ErrorAction Stop }
$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList "https://login.windows.net/$tenantID"
$ccred = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential -ArgumentList $appID,$client_secret
$authenticationResult = $authContext.AcquireTokenAsync("https://graph.microsoft.com", $ccred)
if (!$authenticationResult.Result.AccessToken) { Write-Error "Failed to aquire token!"; return }
$authHeader = @{'Authorization'=$authenticationResult.Result.CreateAuthorizationHeader()}
$uri = "https://graph.microsoft.com/v1.0/reports/getTeamsUserActivityCounts(period='D7')"
$result = Invoke-WebRequest -Headers $AuthHeader -Uri $uri
$teams = ($result.Content | ConvertFrom-Json).Value
Hidafo43
Report only provides the Teams activities by activity type, we can't extract TeamsName from this
Please use below lines to your script to export the data into csv
$resultarray = ConvertFrom-Csv -InputObject $result
$resultarray | Export-Csv "C:\output.csv" -NoTypeInformation
2 Replies
Sort By
- Geetha63Copper Contributor
Hidafo43
Report only provides the Teams activities by activity type, we can't extract TeamsName from this
Please use below lines to your script to export the data into csv
$resultarray = ConvertFrom-Csv -InputObject $result
$resultarray | Export-Csv "C:\output.csv" -NoTypeInformation- dafo43Copper Contributor
Thanks, I can see the column names with the exported CSV, so that's enough to work with.