Nov 09 2018 05:10 AM
Nov 09 2018 05:10 AM
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 csv format.
All I'm wanting to achieve is to retrieve the table header information and the results, is there a way to extrapolate that data out and output to a csv file?
Many thanks,
Steve
Nov 10 2018 02:15 AM
SolutionHi 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
Nov 10 2018 07:02 AM
Nov 10 2018 02:15 AM
SolutionHi 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