Jun 13 2020 05:06 AM
I'm looking to use the Graph API to get some Teams stats using PowerShell - ref . 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
Jun 15 2020 12:48 AM
SolutionHi@dafo43
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
Jun 15 2020 03:01 AM
Thanks, I can see the column names with the exported CSV, so that's enough to work with.
Jun 15 2020 12:48 AM
SolutionHi@dafo43
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