onedrive groottes in Office365 bepalen

Param(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
[string] $Tenantname,
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
[string] $Username,
[Parameter(Position=1, Mandatory=$true, ValueFromPipeline=$true)]
[string] $Password,
[Parameter(Position=2, Mandatory=$false, ValueFromPipeline=$true)]
[string] $OutputFile
)
if ($OutputFile -eq "")
{
$OutputFile="C:\OneDrive_groottes.csv"
}
$Result=@()
$loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
$loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
$loadInfo3 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles")
$AdminURI = "https://" + $Tenantname +"-admin.sharepoint.com"
$OneDrivePrefixUrl="https://" + $Tenantname +"-my.sharepoint.com"
$SecPwd = $Password | ConvertTo-SecureString -AsPlainText -Force
$creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $SecPwd)
$UserCredential = New-Object System.Management.Automation.PSCredential -argumentlist $Username, $SecPwd
$proxyaddr = "$AdminURI/_vti_bin/UserProfileService.asmx?wsdl"
$UserProfileService= New-WebServiceProxy -Uri $proxyaddr -UseDefaultCredential False
$UserProfileService.Credentials = $creds
Write-Progress -activity "Fetching User Profiles" -status "..........."
$strAuthCookie = $creds.GetAuthenticationCookie($AdminURI)
$uri = New-Object System.Uri($AdminURI)
$container = New-Object System.Net.CookieContainer
$container.SetCookies($uri, $strAuthCookie)
$UserProfileService.CookieContainer = $container
$UserProfileResult = $UserProfileService.GetUserProfileByIndex(-1)
Write-Host "Starting- This could take a while."
$NumProfiles = $UserProfileService.GetUserProfileCount()
$i = 1
Connect-SPOService -Url $AdminURI -Credential $UserCredential
While ($UserProfileResult.NextValue -ne -1)
{
Write-Progress -activity "Processing User Profiles" -status "$i out of $NumProfiles completed"
$Prop = $UserProfileResult.UserProfile | Where-Object { $_.Name -eq "PersonalSpace" }
$Url= $Prop.Values[0].Value
if ($Url) {
$siteurl = $OneDrivePrefixUrl + $Url.Substring(0,$Url.Length-1)
$temp = Get-SPOSite $siteurl -Detailed
if($temp)
{
$Result += New-Object PSObject -property @{
UserName = $temp.Title
UserPrincipalName = $temp.Owner
TotalSize_MB = $temp.StorageUsageCurrent
TotalSize_GB = $temp.StorageUsageCurrent/1024
StorageQuota_GB = $temp.StorageQuota/1024
WarningSize_GB =  $temp.StorageQuotaWarningLevel/1024
}
}
}
$UserProfileResult = $UserProfileService.GetUserProfileByIndex($UserProfileResult.NextValue)
$i++
}
$Result | Select-object -property UserName,UserPrincipalName,TotalSize_MB,TotalSize_GB,StorageQuota_GB,WarningSize_GB |Export-CSV $OutputFile -NoTypeInformation -Encoding UTF8
Write-Host "OneDrive for Business Storage Report successfully exported to "$OutputFile -foregroundcolor Green

Geplaatst in Ongecategoriseerd.