Forum Discussion
Anonymous
Nov 09, 2018Microsoft Graph and PowerShell - extracting the data into csv
Hey all, Hoping someone can point me in the right direction please? I'm messing about connecting up PowerShell (using PnP) to the Microsoft Graph API with a view of returning the data into a ...
- Nov 10, 2018
Hi Steve, you can use below powershell script for your need.
Connect-PnPOnline -Scopes "User.Read.All","User.ReadBasic.All","Reports.Read.All"
$accesstoken =Get-PnPAccessToken
$apiUrl = "https://graph.microsoft.com/v1.0/reports/getSharePointSiteUsageFileCounts(period='D7')"
$result = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri $apiUrl -Method Get
#Remove special chars from header
$result = $result.Replace('Report Refresh Date','Report Refresh Date')
#Convert the stream result to an array
$resultarray = ConvertFrom-Csv -InputObject $result
#Export result to CSV
$resultarray | Export-Csv "C:\SiteUsage.csv" -NoTypeInformation
Kevin_Morgan
Nov 10, 2018Iron Contributor
Hi Steve, you can use below powershell script for your need.
Connect-PnPOnline -Scopes "User.Read.All","User.ReadBasic.All","Reports.Read.All"
$accesstoken =Get-PnPAccessToken
$apiUrl = "https://graph.microsoft.com/v1.0/reports/getSharePointSiteUsageFileCounts(period='D7')"
$result = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri $apiUrl -Method Get
#Remove special chars from header
$result = $result.Replace('Report Refresh Date','Report Refresh Date')
#Convert the stream result to an array
$resultarray = ConvertFrom-Csv -InputObject $result
#Export result to CSV
$resultarray | Export-Csv "C:\SiteUsage.csv" -NoTypeInformation
- AnonymousNov 10, 2018Huge thanks for this Kevin!