Forum Discussion
Get Sharepoint site file count with powershell
- Mar 04, 2020
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
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.
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