SOLVED

Get Sharepoint site file count with powershell

%3CLINGO-SUB%20id%3D%22lingo-sub-1184657%22%20slang%3D%22en-US%22%3EGet%20Sharepoint%20site%20file%20count%20with%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1184657%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20everyone%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20hope%20this%20is%20something%20really%20stupid%20and%20can%20be%20done%20easily.%20I%20was%20tasked%20with%20retrieving%20all%20Microsoft%20Teams%20that%20were%20opened%20since%20a%20specific%20date.%20In%20the%20report%2C%20I%20need%20to%20have%20team%20name%20and%20mail%2C%20date%20created%2C%20date%20modified%20and%20file%20count.%3C%2FP%3E%3CP%3EI%20got%20everything%20except%20the%20file%20count.%20And%2C%20I%20don't%20want%20to%20use%20pnp%20module%20because%20I%20was%20able%20to%20get%20my%20data%20with%20the%20SharePoint%20online%20module.%3C%2FP%3E%3CP%3Ecan%20someone%20point%20me%20in%20the%20right%20direction%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%20Rahamim.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1184657%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDocument%20Library%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFiles%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1184959%22%20slang%3D%22en-US%22%3ERe%3A%20Get%20Sharepoint%20site%20file%20count%20with%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1184959%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F255442%22%20target%3D%22_blank%22%3E%40RahamimL%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20number%20of%20files%20are%20available%20in%20new%20SharePoint%20Admin%20center%20you%20can%20easily%20find%20them.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20this%20resolves%20your%20issue.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1185094%22%20slang%3D%22en-US%22%3ERe%3A%20Get%20Sharepoint%20site%20file%20count%20with%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1185094%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F70455%22%20target%3D%22_blank%22%3E%40Alireza%20Rahimifarid%3C%2FA%3Eas%20I%20wrote%2C%20I%20need%20a%20report%20for%20all%20those%20site.%20I%20don't%20want%20to%20do%20it%20manually%20and%20I%20might%20be%20required%20to%20do%20this%20again.%20That%20is%20why%20I%20need%20PowerShell.%20I%20have%20to%20use%20Exchange%20to%20find%20the%20group%20associated%20with%20the%20Team%2C%20and%20when%20it%20was%20created.%20And%20SharePoint%2C%20to%20get%20the%20date%20modified%20parameter%20and%20the%20amount%20of%20files.%20The%20only%20problem%20is%20with%20the%20file%20count.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERahamim.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1208261%22%20slang%3D%22en-US%22%3ERe%3A%20Get%20Sharepoint%20site%20file%20count%20with%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1208261%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20the%20end%20this%20is%20what%20I%20wrote%3A%3C%2FP%3E%3CP%3E%3CFONT%3E%24credentials%20%3D%20Get-Credential%20(Privileged%20user%20in%20tenant)%3CBR%20%2F%3EImport-Module%20ExchangeOnline%3CBR%20%2F%3EImport-Module%20MicrosoftTeams%3CBR%20%2F%3EImport-Module%20Microsoft.Online.SharePoint.PowerShell%3CBR%20%2F%3EConnect-SPOService%20-Url%20%22https%3A%2F%2F(Tenenat)-admin.sharepoint.com%20%22%20-Credential%20%24credentials%3CBR%20%2F%3EConnect-MicrosoftTeams%20-Credential%20%24credentials%3CBR%20%2F%3EConnect-ExchangeOnline%20-Credential%20%24credentials%3CBR%20%2F%3E%24groups%20%3D%20Get-EXORecipient%20-RecipientTypeDetails%20GroupMailbox%20-Properties%20WhenCreated%20%7C%20%3F%20WhenCreated%20-ge%20((Get-Date%20(x.x.xxxx)).ToString())%3CBR%20%2F%3EWrite-Host%20%22Found%22%20%24groups.Count%20%22Groups%2C%20Getting%20search%20team%20by%20group...%22%20-ForegroundColor%20Green%3CBR%20%2F%3E%24table%20%3D%20%24null%3CBR%20%2F%3E%24Table%20%3D%20New-Object%20System.Collections.ArrayList%3CBR%20%2F%3Eforeach(%24group%20in%20%24groups)%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24Line%20%3D%20New-Object%20-TypeName%20psobject%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20if(Get-Team%20-MailNickName%20%24group.Alias)%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Write-host%20%22Found%20Team%22%20%24group.DisplayName%20%22with%20alias%22%20%24group.Alias%20%22getting%20data...%22%20-ForegroundColor%20Green%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Add-Member%20-InputObject%20%24Line%20-MemberType%20NoteProperty%20-Name%20%22DisplayName%22%20-Value%20%24group.DisplayName%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Add-Member%20-InputObject%20%24Line%20-MemberType%20NoteProperty%20-Name%20%22Email%22%20-Value%20%24group.PrimarySmtpAddress%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Add-Member%20-InputObject%20%24Line%20-MemberType%20NoteProperty%20-Name%20%22WhenCreated%22%20-Value%20%24group.WhenCreated.ToString()%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24Sitecheck%20%3D%20%22https%3A%2F%2F(Tenant).sharepoint.com%2Fsites%2F%22%20%2B%20%24group.Alias%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20if((Get-SPOSite%20-Limit%20all%20%7C%20%3F%20Url%20-eq%20%24Sitecheck)%20-ne%20%24null)%7B%24Site%20%3D%20Get-SPOSite%20%24Sitecheck%20%7C%20select%20*%7Delse%7B%24Site%20%3D%20Get-SPOSite%20-Limit%20all%20%7C%20%3F%20Url%20-like%20(%24Sitecheck%20%2B%20%22*%22)%20%7C%20select%20*%7D%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24Site.Url%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Add-Member%20-InputObject%20%24Line%20-MemberType%20NoteProperty%20-Name%20%22DateModified%22%20-Value%20%24Site.LastContentModifiedDate.ToString()%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Add-Member%20-InputObject%20%24Line%20-MemberType%20NoteProperty%20-Name%20%22UsedStorageMB%22%20-Value%20%24Site.StorageUsageCurrent.ToString()%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%5Bvoid%5D%24Table.Add(%24Line)%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3CBR%20%2F%3E%24Table%20%7C%20Export-Csv%20C%3A%5CTemp%5CMS-Teams.csv%20-NoTypeInformation%20-Encoding%20UTF8%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Frequent Contributor

Hi everyone,

 

I hope this is something really stupid and can be done easily. I was tasked with retrieving all Microsoft Teams that were opened since a specific date. In the report, I need to have team name and mail, date created, date modified and file count.

I got everything except the file count. And, I don't want to use pnp module because I was able to get my data with the SharePoint online module.

can someone point me in the right direction?

 

Thanks, Rahamim.

3 Replies
Highlighted

@RahamimL 

The number of files are available in new SharePoint Admin center you can easily find them.

 

Hope this resolves your issue.

 

 

Highlighted

@Alireza Rahimifaridas I wrote, I need a report for all those site. I don't want to do it manually and I might be required to do this again. That is why I need PowerShell. I have to use Exchange to find the group associated with the Team, and when it was created. And SharePoint, to get the date modified parameter and the amount of files. The only problem is with the file count.

 

Rahamim. 

Highlighted
Solution

In the end this is what I wrote:

$credentials = Get-Credential (Privileged user in tenant)
Import-Module ExchangeOnline
Import-Module MicrosoftTeams
Import-Module Microsoft.Online.SharePoint.PowerShell
Connect-SPOService -Url "https://(Tenenat)-admin.sharepoint.com " -Credential $credentials
Connect-MicrosoftTeams -Credential $credentials
Connect-ExchangeOnline -Credential $credentials
$groups = Get-EXORecipient -RecipientTypeDetails GroupMailbox -Properties WhenCreated | ? WhenCreated -ge ((Get-Date (x.x.xxxx)).ToString())
Write-Host "Found" $groups.Count "Groups, Getting search team by group..." -ForegroundColor Green
$table = $null
$Table = New-Object System.Collections.ArrayList
foreach($group in $groups){
    $Line = New-Object -TypeName psobject
    if(Get-Team -MailNickName $group.Alias){
        Write-host "Found Team" $group.DisplayName "with alias" $group.Alias "getting data..." -ForegroundColor Green
        Add-Member -InputObject $Line -MemberType NoteProperty -Name "DisplayName" -Value $group.DisplayName
        Add-Member -InputObject $Line -MemberType NoteProperty -Name "Email" -Value $group.PrimarySmtpAddress
        Add-Member -InputObject $Line -MemberType NoteProperty -Name "WhenCreated" -Value $group.WhenCreated.ToString()
        $Sitecheck = "https://(Tenant).sharepoint.com/sites/" + $group.Alias
        if((Get-SPOSite -Limit all | ? Url -eq $Sitecheck) -ne $null){$Site = Get-SPOSite $Sitecheck | select *}else{$Site = Get-SPOSite -Limit all | ? Url -like ($Sitecheck + "*") | select *}
        $Site.Url
        Add-Member -InputObject $Line -MemberType NoteProperty -Name "DateModified" -Value $Site.LastContentModifiedDate.ToString()
        Add-Member -InputObject $Line -MemberType NoteProperty -Name "UsedStorageMB" -Value $Site.StorageUsageCurrent.ToString()
        [void]$Table.Add($Line)
        }
    }
$Table | Export-Csv C:\Temp\MS-Teams.csv -NoTypeInformation -Encoding UTF8