-1

I am looking for a PowerShell Script that can export a list of our SharePoint users with the information of used quota (Total Quota, Used, Free, ...in Megabytes). I have only found the scripts where are the information such as Address, Telephone number, etc. The best would be, when this script is able to generate xls file.

0

This is the script that I wrote to retrieve Site Collection quota and usage information. The information for user's will be in your MySites and you can easily filter the results to look at only those. You will need to run this script as a SharePoint administrator to ensure that all usage data is properly retrieved.

if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell
}

function Get-SPQuotaTemplate($spSite)
{
    return $spSite.WebApplication.WebService.QuotaTemplates | ?{ $_.QuotaID -eq $spSite.Quota.QuotaID }
}

function Get-SPApplicableQuota($spSite)
{
    [Microsoft.SharePoint.Administration.SPQuota] $spSiteQuota = $spSite.Quota

    if ($spSite.Quota.QuotaID -ne 0)
    {
        $spSiteQuotaTemplate = Get-SPQuotaTemplate $spSite

        if ($spSiteQuotaTemplate -ne $null)
        {
            $spSiteQuota = [Microsoft.SharePoint.Administration.SPQuota] $spSiteQuotaTemplate
        }
    }

    return $spSiteQuota
}

function Get-SPQuotaInfo()
{
    $quotaIDColumn = @{name = 'QuotaID'; expression = { $_.Quota.QuotaID } }
    $quotaTemplateColumn = @{name = 'QuotaTemplate'; expression = { $quotaID = $_.Quota.QuotaID; if ($quotaID -eq 0) { "No Template" } else { ((Get-SPQuotaTemplate $_).Name, "Unknown ($($quotaID))" -ne $null)[0] } } }
    $storageMaximumLevelColumn = @{ name = 'StorageMaximumLevel'; expression = { (Get-SPApplicableQuota $_).StorageMaximumLevel } }
    $storageWarningLevelColumn = @{ name = 'StorageWarningLevel'; expression = { (Get-SPApplicableQuota $_).StorageWarningLevel } }
    $storageUsedColumn = @{ name = 'StorageUsed'; expression = { $_.Usage.Storage } }

    $spQuotaInfo = $null

    # Sites must be retrieved with elevated privileges in order to ensure consistent access to the usage data.
    [Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges({
        [Microsoft.SharePoint.SPSite[]] $spSites = Get-SPSite -Limit ALL
        $spQuotaInfo = $spSites | Select Url, $quotaIDColumn, $quotaTemplateColumn, $storageMaximumLevelColumn, $StorageWarningLevelColumn, $storageUsedColumn

        # Passes the array of PSCustomObjects generated by the Select back out to the parent.
        Set-Variable -Scope 1 -Name spQuotaInfo -Value $spQuotaInfo
    })

    return $spQuotaInfo
}

function Format-QuotaInfoTable($spQuotaInfo)
{
    $quotaTemplateDisplay = @{name = 'Quota Template'; expression = { $_.QuotaTemplate } }
    $storageMaximumLevelDisplay = @{ name = 'Storage Maximum Level'; expression = { if ($_.StorageMaximumLevel -eq 0) { "No Limit" } else { "{0:N0} MB" -f ($_.StorageMaximumLevel / 1048576.0) } }; align = 'right' }
    $storageWarningLevelDisplay = @{ name = 'Storage Warning Level'; expression = { if ($_.StorageWarningLevel -eq 0) { "No Limit" } else { "{0:N0} MB" -f ($_.StorageWarningLevel / 1048576.0) } }; align = 'right' }
    $storageUsedDisplay = @{ name = 'Storage Used'; expression = { $_.StorageUsed / 1048576.0 }; align = 'right'; formatString = '{0:N3} MB' }
    $percentQuotaUsedDisplay = @{ name = 'Quota Used'; expression = { if ($_.StorageMaximumLevel -eq 0) { 0 } else { $_.StorageUsed / $_.StorageMaximumLevel } }; formatString = '{0:P}' }

    $spQuotaInfo | ft -AutoSize Url, $quotaTemplateDisplay, $storageMaximumLevelDisplay, $storageWarningLevelDisplay, $storageUsedDisplay, $percentQuotaUsedDisplay
}

$spQuotaInfo = Get-SPQuotaInfo | Sort StorageUsed -Descending
Format-QuotaInfoTable $spQuotaInfo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.