Forum Discussion

RahamimL's avatar
RahamimL
Iron Contributor
Feb 20, 2020
Solved

Get Sharepoint site file count with powershell

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 ...
  • RahamimL's avatar
    RahamimL
    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

Resources