12Knocksinna / Office365itpros

Office 365 for IT Pros PowerShell examples
MIT License
1.33k stars 577 forks source link

Adjustments needed #107

Closed Dindin-Rules closed 6 months ago

Dindin-Rules commented 6 months ago

Thanks for the recent update. I was able to test and confirm that $headers did pass the token along in this version. Although based on your changes I'm not sure why it didn't in the prior tests I did.

either way, when the report attempts to output the data its still querying "Site URL" which is blank in all the returned data that I received so the $Datatable never gets populated since that value is currently being used as the key.

For example, using the current code as is, I get this as a result for site T-D001* (All of this is from a demo tenant, its not private) (CSV format below) GroupName,ManagedBy,ContactEmail,Visibility,Members,External Guests,Description,Sensitivity Label,Team Enabled,Last Teams message,Number Teams messages,Last Email Inbox,Number Email Inbox,Last SPO Activity,SPO Storage Used (GB),Number SPO Files,SPO Site URL,Date Created,Days Old,NumberWarnings,Status,Overall Result T-D0001_Team,MOD Administrator,admin@.onmicrosoft.com,Private,1,0,T-D0001_Team,,TRUE,,0,Teams-enabled group,N/A,,N/A,0,https://.sharepoint.com/sites/T-D0001_Team2,1/2/2024 16:41,76,2,"Mbx: OK, Document library never created, Low number of Teams conversations",Issues

To fix this I added or changed a few lines 273: $sitenumber = 0 276: $sitenumber++ 296: 'sitenumber' = $sitenumber 303: $DataTable.Add($sitenumber,$SingleSiteData) 419: $GroupNumber++ 488: If ($Datatable[$GroupNumber]) { # Look up hash table to find usage information for the site 489: $ThisSiteData = $Datatable[$GroupNumber]

This is not exactly what I would call best practice or even good code to use as $groupnumber and $sitenumber could be from non matching sites and groups but just to get the data into a table to see if it worked, it did the trick.

Once I did this, the data from the SPO report appeared (All of this is from a demo tenant, its not private) (CSV format below) GroupName,ManagedBy,ContactEmail,Visibility,Members,External Guests,Description,Sensitivity Label,Team Enabled,Last Teams message,Number Teams messages,Last Email Inbox,Number Email Inbox,Last SPO Activity,SPO Storage Used (GB),Number SPO Files,SPO Site URL,Date Created,Days Old,NumberWarnings,Status,Overall Result T-D0001_Team,MOD Administrator,admin@.onmicrosoft.com,Private,1,0,T-D0001_Team,,TRUE,,0,Teams-enabled group,N/A,3/14/2024,5.17 GB,5,https://.sharepoint.com/sites/T-D0001_Team2,1/2/2024 16:41,76,2,"Mbx: OK, Document library never created, Low number of Teams conversations",Issues

Any thoughts on how to get a working key value out of the output data so the $datatable gets populated?

12Knocksinna commented 6 months ago

The problem is that Microsoft still has the issue of not including the site URL in the output from the usage API. To workaround the problem, the script calls the Sites API to find the sites in the tenant and populates a table from this data. Then when we fetch the SPO usage data, the script attempts to match the identifier returned by the usage API with the identifier returned by the Sites API (why the APIs use two different values is weird). In any case, this manages to populate the $DataTable with a site URL and the usage data for a site. There are some edge conditions where the script can't match things up, but it does seem to work.

You're using a number as the key to the $DataTable hash table. I'm not sure that is a reliable key. I want to use the site URL and am hoping that Microsoft gets this issue fixed ASAP. When they do, I shall reverse the changes and all will be well again.